00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 require_once("class_iselect.php");
00027 require_once("class_icard.php");
00028 require_once("class_ispan.php");
00029 require_once("class_ihidden.php");
00030 require_once("class_idate.php");
00031 require_once("class_itext.php");
00032 require_once("class_ifile.php");
00033 require_once('class_acc_ledger.php');
00034 require_once('class_acc_compute.php');
00035 require_once('class_anc_operation.php');
00036 require_once('user_common.php');
00037 require_once('class_acc_payment.php');
00038 require_once('ac_common.php');
00039 require_once('class_own.php');
00040 require_once('class_itva_popup.php');
00041 require_once('class_acc_ledger_fin.php');
00042 require_once 'class_stock_goods.php';
00043
00044
00045
00046
00047
00048
00049 class Acc_Ledger_Sold extends Acc_Ledger {
00050
00051 function __construct($p_cn, $p_init) {
00052 parent::__construct($p_cn, $p_init);
00053 $this->type = 'VEN';
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 public function verify($p_array) {
00063 global $g_parameter, $g_user;
00064 extract($p_array);
00065
00066 if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0)
00067 throw new Exception(_('Double Encodage'), 5);
00068
00069
00070 if ($g_user->check_jrn($p_jrn) != 'W')
00071 throw new Exception(_('Accès interdit'), 20);
00072
00073
00074 if (strlen(trim($e_client)) == 0)
00075 throw new Exception(_('Vous n\'avez pas donné de client'), 11);
00076
00077
00078 if (isDate($e_date) == null) {
00079 throw new Exception(_('Date invalide'), 2);
00080 }
00081
00082 $oPeriode = new Periode($this->db);
00083 if ($this->check_periode() == true) {
00084 $tperiode = $period;
00085
00086 $oPeriode->p_id = $period;
00087 list ($min, $max) = $oPeriode->get_date_limit();
00088
00089 if (cmpDate($e_date, $min) < 0 ||
00090 cmpDate($e_date, $max) > 0)
00091 throw new Exception(_('Date et periode ne correspondent pas'), 6);
00092 }
00093 else {
00094 $per = new Periode($this->db);
00095 $tperiode = $per->find_periode($e_date);
00096 }
00097
00098
00099 if ($this->is_closed($tperiode) == 1) {
00100 throw new Exception(_('Periode fermee'), 6);
00101 }
00102
00103 if ($this->check_strict() == true) {
00104
00105
00106 $last_date = $this->get_last_date();
00107 if ($last_date != null && cmpDate($e_date, $last_date) < 0)
00108 throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
00109 . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 13);
00110 }
00111
00112
00113 $fiche = new Fiche($this->db);
00114 $fiche->get_by_qcode($e_client);
00115 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
00116 throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de poste comptable'), 8);
00117
00118
00119 $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
00120
00121 if (strpos($sposte, ',') != 0) {
00122 $array = explode(',', $sposte);
00123 $poste_val = $array[0];
00124 } else {
00125 $poste_val = $sposte;
00126 }
00127
00128
00129 $poste = new Acc_Account_Ledger($this->db, $poste_val);
00130
00131 if ($poste->load() == false) {
00132 throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste comptable [') . $poste->id . _('] n\'existe pas'), 9);
00133 }
00134
00135
00136 $fiche = new Fiche($this->db);
00137 $fiche->get_by_qcode($e_client, 'deb');
00138 if ($fiche->belong_ledger($p_jrn) != 1)
00139 throw new Exception(_('La fiche ') . $e_client . _('n\'est pas accessible à ce journal'), 10);
00140
00141 $nb = 0;
00142
00143
00144
00145
00146 for ($i = 0; $i < $nb_item; $i++) {
00147 if (strlen(trim(${'e_march' . $i})) == 0)
00148 continue;
00149
00150 if (isNumber(${'e_march' . $i . '_price'}) == 0)
00151 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un montant invalide [') . ${'e_march' . $i} . ']', 6);
00152 if (isNumber(${'e_quant' . $i}) == 0)
00153 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
00154
00155 $fiche = new Fiche($this->db);
00156 $fiche->get_by_qcode(${'e_march' . $i});
00157 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
00158 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'a pas de poste comptable'), 8);
00159
00160
00161 if ($g_parameter->MY_TVA_USE == 'Y') {
00162 if (isNumber(${'e_march' . $i . '_tva_id'}) == 0)
00163 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
00164 $tva_rate = new Acc_Tva($this->db);
00165 $tva_rate->set_parameter('id', ${'e_march' . $i . '_tva_id'});
00166 if ($tva_rate->load() != 0)
00167 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
00168
00169
00170
00171
00172 $a_poste = explode(',', $tva_rate->tva_poste);
00173
00174 if (
00175 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[0])) == 0 ||
00176 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[1])) == 0)
00177 throw new Exception(_(" La TVA " . $tva_rate->tva_label . " utilise des postes comptables inexistants"));
00178 }
00179
00180
00181 $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
00182
00183 if (strpos($sposte, ',') != 0) {
00184 $array = explode(',', $sposte);
00185 $poste_val = $array[1];
00186 } else {
00187 $poste_val = $sposte;
00188 }
00189 $poste = new Acc_Account_Ledger($this->db, $poste_val);
00190 if ($poste->load() == false) {
00191 throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . _(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
00192 }
00193
00194 $fiche = new Fiche($this->db);
00195 $fiche->get_by_qcode(${'e_march' . $i});
00196 if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
00197 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'est pas accessible à ce journal'), 10);
00198 $nb++;
00199 }
00200 if ($nb == 0)
00201 throw new Exception(_('Il n\'y a aucune marchandise'), 12);
00202
00203
00204
00205
00206 if ($e_mp != 0) {
00207 $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
00208 }
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 public function insert($p_array = null) {
00221 global $g_parameter;
00222 extract($p_array);
00223 $this->verify($p_array);
00224
00225 $group = $this->db->get_next_seq("s_oa_group");
00226 $seq = $this->db->get_next_seq('s_grpt');
00227 $this->id = $p_jrn;
00228 $internal = $this->compute_internal_code($seq);
00229 $this->internal = $internal;
00230
00231 $oPeriode = new Periode($this->db);
00232 $check_periode = $this->check_periode();
00233
00234 if ($check_periode == true)
00235 $tperiode = $period;
00236 else
00237 $tperiode = $oPeriode->find_periode($e_date);
00238
00239 $cust = new Fiche($this->db);
00240 $cust->get_by_qcode($e_client);
00241 $sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
00242
00243
00244
00245 if (strpos($sposte, ',') != 0) {
00246 $array = explode(',', $sposte);
00247 $poste = $array[0];
00248 } else {
00249 $poste = $sposte;
00250 }
00251
00252 bcscale(4);
00253 try {
00254 $tot_amount = 0;
00255 $tot_tva = 0;
00256 $tot_debit = 0;
00257 $this->db->start();
00258 $tva = array();
00259
00260 for ($i = 0; $i < $nb_item; $i++) {
00261 $n_both = 0;
00262 if (strlen(trim(${'e_march' . $i})) == 0)
00263 continue;
00264
00265
00266 $fiche = new Fiche($this->db);
00267 $fiche->get_by_qcode(${"e_march" . $i});
00268 $amount = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
00269 $tot_amount = bcadd($tot_amount, $amount);
00270 $acc_operation = new Acc_Operation($this->db);
00271 $acc_operation->date = $e_date;
00272 $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
00273
00274
00275 if (strpos($sposte, ',') != 0) {
00276 $array = explode(',', $sposte);
00277 $poste_val = $array[1];
00278 } else {
00279 $poste_val = $sposte;
00280 }
00281
00282 $acc_operation->poste = $poste_val;
00283 $acc_operation->amount = $amount;
00284 $acc_operation->grpt = $seq;
00285 $acc_operation->jrn = $p_jrn;
00286 $acc_operation->type = 'c';
00287 $acc_operation->periode = $tperiode;
00288 if ($g_parameter->MY_UPDLAB == 'Y')
00289 $acc_operation->desc = strip_tags(${"e_march" . $i . "_label"});
00290 else
00291 $acc_operation->desc = null;
00292
00293 $acc_operation->qcode = ${"e_march" . $i};
00294 if ($amount < 0)
00295 $tot_debit = bcadd($tot_debit, abs($amount));
00296
00297 $j_id = $acc_operation->insert_jrnx();
00298
00299 if ($g_parameter->MY_TVA_USE == 'Y') {
00300
00301 $oTva = new Acc_Tva($this->db);
00302 $idx_tva = ${'e_march' . $i . '_tva_id'};
00303 $tva_item = ${'e_march' . $i . '_tva_amount'};
00304 $oTva->set_parameter("id", $idx_tva);
00305 $oTva->load();
00306
00307 if (trim($tva_item) == '') {
00308
00309 $l = new Acc_Tva($this->db, $idx_tva);
00310 $l->load();
00311 $tva_item = bcmul($amount, $l->get_parameter('rate'));
00312 }
00313 if (isset($tva[$idx_tva]))
00314 $tva[$idx_tva]+=$tva_item;
00315 else
00316 $tva[$idx_tva] = $tva_item;
00317 if ($oTva->get_parameter("both_side") == 0) {
00318 $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
00319 } else {
00320 $n_both = $tva_item;
00321 if ($n_both < 0)
00322 $tot_debit = bcadd($tot_debit, abs($n_both));
00323 }
00324 }
00325
00326
00327
00328
00329
00330 $nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
00331
00332
00333
00334 if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
00335 {
00336 $dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
00337 Stock_Goods::insert_goods($this->db, array('j_id' => $j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 'dir' => $dir, 'repo' => $repo));
00338 }
00339
00340
00341 if ($g_parameter->MY_ANALYTIC != "nu") {
00342
00343 $op = new Anc_Operation($this->db);
00344 $op->oa_group = $group;
00345 $op->j_id = $j_id;
00346 $op->oa_date = $e_date;
00347 $op->oa_debit = ($amount < 0 ) ? 't' : 'f';
00348 $op->oa_description = sql_string($e_comm);
00349 $op->save_form_plan($_POST, $i, $j_id);
00350 }
00351 if ($g_parameter->MY_TVA_USE == 'Y') {
00352
00353 $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9)", array(null,
00354 $j_id,
00355 ${'e_march' . $i},
00356 ${'e_quant' . $i},
00357 round($amount, 2),
00358 $tva_item,
00359 $idx_tva,
00360 $e_client,
00361 $n_both));
00362 } else {
00363 $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9) ", array(null,
00364 $j_id,
00365 ${'e_march' . $i},
00366 ${'e_quant' . $i},
00367 $amount,
00368 0,
00369 null,
00370 $e_client,
00371 0));
00372 }
00373 }
00374
00375
00376 $cust_amount = bcadd($tot_amount, $tot_tva);
00377 $acc_operation = new Acc_Operation($this->db);
00378 $acc_operation->date = $e_date;
00379 $acc_operation->poste = $poste;
00380 $acc_operation->amount = $cust_amount;
00381 $acc_operation->grpt = $seq;
00382 $acc_operation->jrn = $p_jrn;
00383 $acc_operation->type = 'd';
00384 $acc_operation->periode = $tperiode;
00385 $acc_operation->qcode = ${"e_client"};
00386 if ($cust_amount > 0)
00387 $tot_debit = bcadd($tot_debit, $cust_amount);
00388 $let_tiers = $acc_operation->insert_jrnx();
00389
00390
00391
00392
00393
00394
00395 if ($g_parameter->MY_TVA_USE == 'Y') {
00396 foreach ($tva as $i => $value) {
00397 $oTva = new Acc_Tva($this->db);
00398 $oTva->set_parameter('id', $i);
00399 $oTva->load();
00400
00401 $poste_vat = $oTva->get_side('c');
00402
00403 $cust_amount = bcadd($tot_amount, $tot_tva);
00404 $acc_operation = new Acc_Operation($this->db);
00405 $acc_operation->date = $e_date;
00406 $acc_operation->poste = $poste_vat;
00407 $acc_operation->amount = $value;
00408 $acc_operation->grpt = $seq;
00409 $acc_operation->jrn = $p_jrn;
00410 $acc_operation->type = 'c';
00411 $acc_operation->periode = $tperiode;
00412 if ($value < 0)
00413 $tot_debit = bcadd($tot_debit, abs($value));
00414 $acc_operation->insert_jrnx();
00415
00416
00417 if ($oTva->get_parameter("both_side") == 1) {
00418 $poste_vat = $oTva->get_side('d');
00419 $cust_amount = bcadd($tot_amount, $tot_tva);
00420 $acc_operation = new Acc_Operation($this->db);
00421 $acc_operation->date = $e_date;
00422 $acc_operation->poste = $poste_vat;
00423 $acc_operation->amount = $value;
00424 $acc_operation->grpt = $seq;
00425 $acc_operation->jrn = $p_jrn;
00426 $acc_operation->type = 'd';
00427 $acc_operation->periode = $tperiode;
00428 $acc_operation->insert_jrnx();
00429 $tot_debit = bcadd($tot_debit, $value);
00430 $n_both = $value;
00431 }
00432 }
00433 }
00434
00435 $acc_operation = new Acc_Operation($this->db);
00436 $acc_operation->date = $e_date;
00437 $acc_operation->echeance = $e_ech;
00438 $acc_operation->amount = abs(round($tot_debit, 2));
00439 $acc_operation->desc = $e_comm;
00440 $acc_operation->grpt = $seq;
00441 $acc_operation->jrn = $p_jrn;
00442 $acc_operation->periode = $tperiode;
00443 $acc_operation->pj = $e_pj;
00444 $acc_operation->mt = $mt;
00445
00446 $this->jr_id = $acc_operation->insert_jrn();
00447
00448 $this->pj = $acc_operation->set_pj();
00449
00450
00451
00452 if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) {
00453 $this->inc_seq_pj();
00454 }
00455
00456 $this->db->exec_sql("update jrn set jr_internal='" . $internal . "' where " .
00457 " jr_grpt_id = " . $seq);
00458
00459
00460 $this->db->exec_sql('update quant_sold set qs_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $seq));
00461
00462
00463 if (isset($_FILES['pj'])) {
00464 if (strlen(trim($_FILES['pj']['name'])) != 0)
00465 $this->db->save_upload_document($seq);
00466 else
00467
00468 if (isset($_POST['gen_invoice'])) {
00469 $file = $this->create_document($internal, $p_array);
00470 $this->doc='<A class="line" HREF="show_pj.php?' . dossier::get() . '&jr_grpt_id=' . $seq . '&jrn=' . $this->id . '">' . $file . '</A>';
00471 }
00472 }
00473
00474
00475
00476 if ($e_mp != 0) {
00477
00478 $mp = new Acc_Payment($this->db, $e_mp);
00479 $mp->load();
00480
00481
00482 $fqcode = ${'e_mp_qcode_' . $e_mp};
00483 $acfiche = new Fiche($this->db);
00484 $acfiche->get_by_qcode($fqcode);
00485
00486
00487 $acseq = $this->db->get_next_seq('s_grpt');
00488 $acjrn = new Acc_Ledger($this->db, $mp->get_parameter('ledger_target'));
00489 $acinternal = $acjrn->compute_internal_code($acseq);
00490
00491
00492 $acc_pay = new Acc_Operation($this->db);
00493 $acc_pay->date = $e_date;
00494
00495 $sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
00496
00497 if (strpos($sposte, ',') != 0) {
00498 $array = explode(',', $sposte);
00499 $poste_val = $array[0];
00500 } else {
00501 $poste_val = $sposte;
00502 }
00503 $famount = bcsub($cust_amount, $acompte);
00504 $acc_pay->poste = $poste_val;
00505 $acc_pay->qcode = $fqcode;
00506 $acc_pay->amount = abs(round($famount, 2));
00507 $acc_pay->desc = null;
00508
00509 $acc_pay->grpt = $acseq;
00510 $acc_pay->jrn = $mp->get_parameter('ledger_target');
00511 $acc_pay->periode = $tperiode;
00512 $acc_pay->type = ($famount >= 0) ? 'd' : 'c';
00513 $acc_pay->insert_jrnx();
00514
00515
00516 $acc_pay = new Acc_Operation($this->db);
00517 $acc_pay->date = $e_date;
00518 $acc_pay->poste = $poste;
00519 $acc_pay->qcode = $e_client;
00520 $acc_pay->amount = abs(round($famount, 2));
00521 $acc_pay->desc = null;
00522 $acc_pay->grpt = $acseq;
00523 $acc_pay->jrn = $mp->get_parameter('ledger_target');
00524 $acc_pay->periode = $tperiode;
00525 $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
00526 $let_other = $acc_pay->insert_jrnx();
00527
00528
00529 $acc_pay->mt = $mt;
00530 $acjrn->grpt_id = $acseq;
00531 $acc_pay->desc = (!isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0) ? $e_comm : $e_comm_paiement;
00532 $mp_jr_id = $acc_pay->insert_jrn();
00533 $acjrn->update_internal_code($acinternal);
00534
00535 $r1 = $this->get_id($internal);
00536 $r2 = $this->get_id($acinternal);
00537
00538
00539
00540
00541 $oletter = new Lettering($this->db);
00542 $oletter->insert_couple($let_tiers, $let_other);
00543
00544
00545
00546 $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($r1));
00547
00548
00549 $rec = new Acc_Reconciliation($this->db);
00550 $rec->set_jr_id($r1);
00551 $rec->insert($r2);
00552
00553
00554
00555
00556
00557
00558
00559 $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
00560 $prop = $ledger->get_propertie();
00561
00562
00563 if ($prop['jrn_def_type'] == 'FIN') {
00564 $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1));
00565 }
00566 }
00567 } catch (Exception $e) {
00568 echo '<span class="error">' .
00569 'Erreur dans l\'enregistrement ' .
00570 __FILE__ . ':' . __LINE__ . ' ' .
00571 $e->getMessage();
00572 echo $e->getTrace();
00573
00574 $this->db->rollback();
00575 exit();
00576 }
00577 $this->db->commit();
00578
00579 return $internal;
00580 }
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591 function confirm($p_array, $p_summary = false) {
00592 global $g_parameter;
00593 extract($p_array);
00594
00595
00596 if (!$p_summary)
00597 $this->verify($p_array);
00598 $anc = null;
00599
00600
00601
00602 bcscale(4);
00603 $client = new Fiche($this->db);
00604 $client->get_by_qcode($e_client, true);
00605
00606 $client_name = $client->getName() .
00607 ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' .
00608 $client->strAttribut(ATTR_DEF_CP) . ' ' .
00609 $client->strAttribut(ATTR_DEF_CITY);
00610 $lPeriode = new Periode($this->db);
00611 if ($this->check_periode() == true) {
00612 $lPeriode->p_id = $period;
00613 } else {
00614 $lPeriode->find_periode($e_date);
00615 }
00616 $date_limit = $lPeriode->get_date_limit();
00617 $r = "";
00618
00619 $r.='<TABLE>';
00620 if ( $p_summary ) {
00621 $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal));
00622 $r.="<tr>";
00623 $r.='<td>';
00624 $r.=_('Détail opération ');
00625 $r.='</td>';
00626 $r.='<td>';
00627 $r.=sprintf ('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
00628 $jr_id,dossier::id(),$this->internal);
00629 $r.='</td>';
00630 $r.="</tr>";
00631 }
00632 $r.='<tr>';
00633 if ( ! $p_summary) {
00634 $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
00635 } else {
00636
00637 if ( strcmp($this->pj,$e_pj) != 0 )
00638 {
00639 $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) .
00640 '<span class="notice"> '._('Attention numéro pièce existante, elle a du être adaptée').'</span></td>';
00641 } else {
00642 $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . '</td>';
00643 }
00644 }
00645 $r.='</tr>';
00646 $r.='<tr>';
00647 $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
00648 $r.='</tr>';
00649 $r.='<tr>';
00650 $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
00651 $r.='</tr>';
00652 $r.='<tr>';
00653 $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
00654 $r.='</tr>';
00655 $r.='<tr>';
00656 $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
00657 $r.='</tr>';
00658 $r.='<tr>';
00659 $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
00660 $r.='</tr>';
00661
00662 $r.='<tr>';
00663 $r.='<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
00664 $r.='</tr>';
00665 $r.='</table>';
00666 $r.='<h2>' . _('Détail articles vendus') . '</h2>';
00667 $r.='<p class="decale">';
00668 $r.='<table class="result" >';
00669 $r.='<TR>';
00670 $r.="<th>" . _('Code') . "</th>";
00671 $r.="<th>" . _('Dénomination') . "</th>";
00672 $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
00673 $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
00674
00675
00676 if ($g_parameter->MY_TVA_USE == 'Y') {
00677 $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
00678 $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
00679 $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
00680 $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
00681 } else {
00682 $r.='<th style="text-align:right">' . _('Montant') . '</th>';
00683 }
00684
00685 if ($g_parameter->MY_ANALYTIC != 'nu') {
00686 $anc = new Anc_Plan($this->db);
00687 $a_anc = $anc->get_list();
00688 $x = count($a_anc);
00689
00690 $r.='<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
00691
00692
00693 $r.=Anc_Plan::hidden($a_anc);
00694 }
00695 $r.='</tr>';
00696 $tot_amount = 0.0;
00697 $tot_tva = 0.0;
00698 for ($i = 0; $i < $nb_item; $i++) {
00699 if (strlen(trim(${"e_march" . $i})) == 0)
00700 continue;
00701
00702
00703 $fiche = new Fiche($this->db);
00704 $fiche->get_by_qcode(${"e_march" . $i});
00705 if ($g_parameter->MY_UPDLAB == 'Y')
00706 $fiche_name = h(${"e_march" . $i . "_label"});
00707 else
00708 $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
00709 if ($g_parameter->MY_TVA_USE == 'Y') {
00710 $oTva = new Acc_Tva($this->db);
00711 $idx_tva = ${"e_march" . $i . "_tva_id"};
00712
00713 $oTva->set_parameter('id', $idx_tva);
00714 $oTva->load();
00715 }
00716 $op = new Acc_Compute();
00717 $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
00718 $op->set_parameter("amount", $amount);
00719 if ($g_parameter->MY_TVA_USE == 'Y') {
00720 $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
00721 $op->compute_vat();
00722 $tva_computed = $op->get_parameter('amount_vat');
00723 $tva_item = ${"e_march" . $i . "_tva_amount"};
00724 if (isset($tva[$idx_tva]))
00725 $tva[$idx_tva]+=$tva_item;
00726 else
00727 $tva[$idx_tva] = $tva_item;
00728 $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
00729 }
00730 $tot_amount = round(bcadd($tot_amount, $amount), 2);
00731
00732 $r.='<tr>';
00733 $r.='<td>';
00734 $r.=${"e_march" . $i};
00735 $r.='</td>';
00736 $r.='<TD style="border-bottom:1px dotted grey;">';
00737 $r.=$fiche_name;
00738 $r.='</td>';
00739 $r.='<td class="num">';
00740 $r.=nbm(${"e_march" . $i . "_price"});
00741 $r.='</td>';
00742 $r.='<td class="num">';
00743 $r.=nbm(${"e_quant" . $i});
00744 $r.='</td>';
00745 if ($g_parameter->MY_TVA_USE == 'Y') {
00746 $r.='<td class="num">';
00747 $r.=$oTva->get_parameter('label');
00748 $r.='</td>';
00749
00750
00751
00752 if (bcsub($tva_item, $tva_computed) != 0) {
00753 $r.='<td style="background-color:red" class="num">';
00754 $r.=HtmlInput::infobulle(28);
00755 $r.='<a href="#" class="error" style="display:inline" title="' . _("Attention Différence entre TVA calculée et donnée") . '">'
00756 . nbm($tva_item) . '<a>';
00757 } else {
00758 $r.='<td class="num">';
00759 $r.=nbm($tva_item);
00760 }
00761 $r.='</td>';
00762 $r.='<td class="num">';
00763 $r.=nbm($amount);
00764 $r.='</td>';
00765 $tot_row = bcadd($tva_item, $amount);
00766 $r.=td(nbm($tot_row), 'class="num"');
00767 } else {
00768 $r.='<td class="num">';
00769 $r.=nbm($amount);
00770 $r.='</td>';
00771 }
00772
00773 if ($g_parameter->MY_ANALYTIC != 'nu') {
00774
00775 $anc_op = new Anc_Operation($this->db);
00776 $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
00777 $r.='<td>';
00778 $p_mode = ($p_summary == false) ? 1 : 0;
00779 $p_array['pa_id'] = $a_anc;
00780
00781 $r.=HtmlInput::hidden('op[]=', $i);
00782 $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, $amount);
00783 $r.='</td>';
00784 }
00785
00786
00787 $r.='</tr>';
00788 }
00789
00790
00791 $r.='</table>';
00792 $r.='</p>';
00793 if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary)
00794 $r.='<input type="button" class="button" value="' . _('Vérifiez Imputation Analytique') . '" onClick="verify_ca(\'\');">';
00795 $r.='<h2>Totaux</h2>';
00796 $r.='<p class="decale">';
00797 $tot = round(bcadd($tot_amount, $tot_tva), 2);
00798
00799 if ($g_parameter->MY_TVA_USE == 'Y') {
00800 $r.='<table>';
00801 $r.='<tr><td>Total HTVA</td>';
00802 $r.=td(hb(nbm($tot_amount) ),'class="num"');
00803 foreach ($tva as $i => $value) {
00804 $oTva->set_parameter('id', $i);
00805 $oTva->load();
00806
00807 $r.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';
00808 $r.=td(hb(nbm($tva[$i])),'class="num"');
00809 }
00810 $r.='<tr>'.td(_('Total TVA')).td(hb(nbm($tot_tva)),'class="num"');
00811 $r.='<tr>'.td(_('Total TVAC')).td(hb(nbm($tot)),'class="num"');
00812 $r.='</table>';
00813 } else {
00814 $r.='<br>Total '.hb(nbm($tot));
00815 }
00816 $r.='</p>';
00817 if (!$p_summary) {
00818 $r.=$this->extra_info();
00819 }
00820
00821
00822
00823
00824 $r.=HtmlInput::hidden('e_client', $e_client);
00825 $r.=HtmlInput::hidden('nb_item', $nb_item);
00826 $r.=HtmlInput::hidden('p_jrn', $p_jrn);
00827 $mt = microtime(true);
00828 $r.=HtmlInput::hidden('mt', $mt);
00829
00830 if (isset($period))
00831 $r.=HtmlInput::hidden('period', $period);
00832
00833 $r.=HtmlInput::hidden('e_comm', $e_comm);
00834 $r.=HtmlInput::hidden('e_date', $e_date);
00835 $r.=HtmlInput::hidden('e_ech', $e_ech);
00836 $r.=HtmlInput::hidden('e_pj', $e_pj);
00837 $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
00838
00839 $e_mp = (isset($e_mp)) ? $e_mp : 0;
00840 $r.=HtmlInput::hidden('e_mp', $e_mp);
00841
00842 if ($g_parameter->MY_STOCK == 'Y') {
00843 $sel = HtmlInput::select_stock($this->db, 'repo', 'W');
00844 $sel->readOnly = $p_summary;
00845 if ($p_summary == true)
00846 $sel->selected = $repo;
00847 $r.='<h2>Dépôt</h2>';
00848 $r.="<p class=\"decale\"> Dans le dépôt : ";
00849 $r.=$sel->input();
00850 $r.='</p>';
00851 }
00852
00853
00854 if ($e_mp != 0 && strlen(trim(${'e_mp_qcode_' . $e_mp})) != 0) {
00855 $r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp});
00856 $r.=HtmlInput::hidden('acompte', $acompte);
00857 $r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
00858
00859 $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
00860
00861 $fname = new Fiche($this->db);
00862 $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
00863 $r.='<h2>' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
00864 " " . $fname->getName() . '</H2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' .
00865 _('Libellé :') . h($e_comm_paiement) ;
00866 $r.='<br>';
00867 }
00868
00869 $r.=HtmlInput::hidden('jrn_type', $jrn_type);
00870 for ($i = 0; $i < $nb_item; $i++) {
00871 $r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
00872 if (isset(${"e_march" . $i . "_label"}))
00873 $r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"});
00874 $r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"});
00875 if ($g_parameter->MY_TVA_USE == 'Y') {
00876 $r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"});
00877 $r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", ${"e_march" . $i . "_tva_amount"});
00878 }
00879 $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
00880 }
00881 return $r;
00882 }
00883
00884
00885
00886
00887
00888
00889
00890
00891 public function extra_info() {
00892 $r = "";
00893 $r.='<h2> Facturation</h2>';
00894
00895 $file = new IFile();
00896 $file->table = 0;
00897 $r.='<p class="decale">';
00898 $r.=_("Ajoutez une pièce justificative ");
00899 $r.=$file->input("pj", "");
00900
00901 if ($this->db->count_sql("select md_id,md_name from document_modele where md_affect='VEN'") > 0) {
00902
00903
00904 $r.=_('ou générer une facture') . ' <input type="checkbox" name="gen_invoice" CHECKED>';
00905
00906 $doc_gen = new ISelect();
00907 $doc_gen->name = "gen_doc";
00908 $doc_gen->value = $this->db->make_array(
00909 "select md_id,md_name " .
00910 " from document_modele where md_affect='VEN'");
00911 $r.=$doc_gen->input() . '<br>';
00912 }
00913 $r.='<br>';
00914 $obj = new IText();
00915 $r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . '<br>';
00916 $r.=_('Autre information : ') . $obj->input('other_info') . '<br>';
00917 $r.='</p>';
00918 return $r;
00919 }
00920
00921
00922
00923
00924 function show_unpaid() {
00925
00926
00927
00928 $step = $_SESSION['g_pagesize'];
00929 $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
00930 $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
00931
00932
00933 $sql = SQL_LIST_UNPAID_INVOICE_DATE_LIMIT . " and jr_def_id=" . $this->id;
00934 list($max_line, $list) = ListJrn($this->db, $sql, null, $offset, 1);
00935 $sql = SQL_LIST_UNPAID_INVOICE . " and jr_def_id=" . $this->id;
00936 list($max_line2, $list2) = ListJrn($this->db, $sql, null, $offset, 1);
00937
00938
00939 $m = ($max_line2 > $max_line) ? $max_line2 : $max_line;
00940 $bar2 = navigation_bar($offset, $m, $step, $page);
00941
00942 echo $bar2;
00943 echo '<h2 class="info"> ' . _('Echeance dépassée') . ' </h2>';
00944 echo $list;
00945 echo '<h2 class="info"> ' . _('Non Payée') . ' </h2>';
00946 echo $list2;
00947 echo $bar2;
00948
00949 $hid = new IHidden();
00950
00951 echo '<hr>';
00952
00953 if ($m != 0)
00954 echo HtmlInput::submit('paid', _('Mise à jour paiement'));
00955 }
00956
00957
00958
00959
00960
00961
00962
00963 function input($p_array = null, $p_readonly = 0) {
00964 global $g_parameter, $g_user;
00965 if ($p_array != null)
00966 extract($p_array);
00967
00968 $flag_tva = $g_parameter->MY_TVA_USE;
00969
00970 $f_add_button = new IButton('add_card');
00971 $f_add_button->tabindex = -1;
00972 $f_add_button->label = _('Créer une nouvelle fiche');
00973 $f_add_button->set_attribute('ipopup', 'ipop_newcard');
00974 $f_add_button->set_attribute('jrn', $this->id);
00975 $f_add_button->javascript = "this.jrn=\$('p_jrn').value; select_card_type(this);";
00976
00977 $f_add_button2 = new IButton('add_card2');
00978 $f_add_button2->tabindex = -1;
00979 $f_add_button2->label = _('Créer une nouvelle fiche');
00980 $f_add_button2->set_attribute('ipopup', 'ipop_newcard');
00981 $f_add_button2->set_attribute('filter', $this->get_all_fiche_def());
00982
00983 $f_add_button2->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
00984
00985 $str_add_button = "";
00986 $str_add_button2 = "";
00987 if ($g_user->check_action(FICADD) == 1) {
00988 $str_add_button = $f_add_button->input();
00989 $str_add_button2 = $f_add_button2->input();
00990 }
00991
00992 $oPeriode = new Periode($this->db);
00993 list ($l_date_start, $l_date_end) = $oPeriode->get_date_limit($g_user->get_periode());
00994 if ($g_parameter->MY_DATE_SUGGEST == 'Y')
00995 $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
00996 else
00997 $op_date = (!isset($e_date) ) ? '' : $e_date;
00998
00999
01000 $e_ech = (isset($e_ech)) ? $e_ech : "";
01001 $e_comm = (isset($e_comm)) ? $e_comm : "";
01002
01003 $r = '';
01004 $r.=dossier::hidden();
01005 $f_legend = _('Client');
01006
01007 $Echeance = new IDate();
01008 $Echeance->setReadOnly(false);
01009
01010 $Echeance->tabindex = 2;
01011 $label = HtmlInput::infobulle(4);
01012 $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . $label);
01013 $Date = new IDate();
01014 $Date->setReadOnly(false);
01015
01016 $f_date = $Date->input("e_date", $op_date);
01017
01018 $f_periode = '';
01019
01020
01021 if ($this->check_periode() == true) {
01022 $l_user_per = $g_user->get_periode();
01023 $def = (isset($periode)) ? $periode : $l_user_per;
01024
01025 $period = new IPeriod("period");
01026 $period->user = $g_user;
01027 $period->cn = $this->db;
01028 $period->value = $def;
01029 $period->type = OPEN;
01030 try {
01031 $l_form_per = $period->input();
01032 } catch (Exception $e) {
01033 if ($e->getCode() == 1) {
01034 echo _("Aucune période ouverte");
01035 exit();
01036 }
01037 }
01038 $label = HtmlInput::infobulle(3);
01039 $f_periode = '<td>' . _("Période comptable") . "</td> <td> $label " . $l_form_per . '</td>';
01040 }
01041
01042 $add_js = "";
01043 if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
01044 $add_js = "update_pj();";
01045 }
01046 if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
01047 $add_js.='get_last_date();';
01048 }
01049 $add_js.='update_name();';
01050 $add_js.='update_pay_method();';
01051 $add_js.='update_row("sold_item");';
01052
01053 $wLedger = $this->select_ledger('VEN', 2);
01054 if ($wLedger == null)
01055 exit(_('Pas de journal disponible'));
01056 $wLedger->table = 1;
01057 $wLedger->javascript = "onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
01058 $wLedger->label = " Journal " . HtmlInput::infobulle(2);
01059
01060 $f_jrn = $wLedger->input();
01061
01062 $Commentaire = new IText();
01063 $Commentaire->table = 0;
01064 $Commentaire->setReadOnly(false);
01065 $Commentaire->size = 60;
01066 $Commentaire->tabindex = 3;
01067
01068 $label = HtmlInput::infobulle(1);
01069
01070 $f_desc = $Commentaire->input("e_comm", h($e_comm)) . $label;
01071
01072
01073
01074 $default_pj = '';
01075 if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
01076 $default_pj = $this->guess_pj();
01077 }
01078
01079 $pj = new IText();
01080
01081 $pj->table = 0;
01082 $pj->name = "e_pj";
01083 $pj->size = 10;
01084 $pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
01085 $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
01086
01087
01088 $fiche = 'deb';
01089
01090
01091
01092 $e_client = ( isset($e_client) ) ? $e_client : "";
01093 $e_client_label = " ";
01094
01095
01096
01097 if (strlen(trim($e_client)) != 0) {
01098 $fClient = new Fiche($this->db);
01099 $fClient->get_by_qcode($e_client);
01100 $e_client_label = $fClient->strAttribut(ATTR_DEF_NAME) . ' ' .
01101 ' Adresse : ' . $fClient->strAttribut(ATTR_DEF_ADRESS) . ' ' .
01102 $fClient->strAttribut(ATTR_DEF_CP) . ' ' .
01103 $fClient->strAttribut(ATTR_DEF_CITY) . ' ';
01104 }
01105
01106 $W1 = new ICard();
01107 $W1->label = "Client " . HtmlInput::infobulle(0);
01108 $W1->name = "e_client";
01109 $W1->tabindex = 3;
01110 $W1->value = $e_client;
01111 $W1->table = 0;
01112 $W1->set_dblclick("fill_ipopcard(this);");
01113 $W1->set_attribute('ipopup', 'ipopcard');
01114
01115
01116 $W1->set_attribute('label', 'e_client_label');
01117
01118 $W1->set_attribute('typecard', 'deb');
01119
01120
01121 $W1->set_callback('filter_card');
01122 $W1->set_function('fill_data');
01123 $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
01124 $f_client_qcode = $W1->input();
01125 $client_label = new ISpan();
01126 $client_label->table = 0;
01127 $f_client = $client_label->input("e_client_label", $e_client_label);
01128 $f_client_bt = $W1->search();
01129
01130
01131
01132 $Hid = new IHidden();
01133 $p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
01134 $r.=$Hid->input("nb_item", $p_article);
01135 $max = ($p_article < $this->get_min_row()) ? $this->get_min_row() : $p_article;
01136
01137
01138 $f_legend_detail = _("Détail articles vendus");
01139
01140
01141
01142 for ($i = 0; $i < $max; $i++) {
01143
01144
01145 $march = (isset(${"e_march$i"})) ? ${"e_march$i"} : ""
01146 ;
01147 $march_price = (isset(${"e_march" . $i . "_price"})) ? ${"e_march" . $i . "_price"} : ""
01148 ;
01149 if ($flag_tva == 'Y') {
01150 $march_tva_id = (isset(${"e_march$i" . "_tva_id"})) ? ${"e_march$i" . "_tva_id"} : "";
01151 $march_tva_amount = (isset(${"e_march$i" . "_tva_amount"})) ? ${"e_march$i" . "_tva_amount"} : "";
01152 }
01153 $march_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" . $i . "_label"} : "";
01154
01155
01156
01157 if (strlen(trim($march)) != 0 && strlen(trim($march_label)) == 0) {
01158 $fMarch = new Fiche($this->db);
01159 $fMarch->get_by_qcode($march);
01160 $march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
01161 if ($flag_tva == 'Y') {
01162 if (!(isset(${"e_march$i" . "_tva_id"})))
01163 $march_tva_id = $fMarch->strAttribut(ATTR_DEF_TVA);
01164 }
01165 }
01166
01167
01168 $W1 = new ICard();
01169 $W1->label = "";
01170 $W1->name = "e_march" . $i;
01171 $W1->value = $march;
01172 $W1->table = 1;
01173 $W1->set_attribute('typecard', 'cred');
01174 $W1->set_dblclick("fill_ipopcard(this);");
01175 $W1->set_attribute('ipopup', 'ipopcard');
01176
01177
01178 $W1->set_attribute('label', 'e_march' . $i . '_label');
01179
01180 $W1->set_attribute('price', 'e_march' . $i . '_price');
01181
01182 $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
01183
01184 $W1->set_callback('filter_card');
01185 $W1->set_function('fill_data');
01186 $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
01187
01188 $W1->readonly = false;
01189
01190 $array[$i]['quick_code'] = $W1->input();
01191 $array[$i]['bt'] = $W1->search();
01192
01193 $array[$i]['hidden'] = '';
01194 if ($flag_tva == 'Y')
01195 $array[$i]['hidden'].=HtmlInput::hidden('tva_march' . $i, 0);
01196
01197 $htva = new INum('htva_march' . $i);
01198 $htva->readOnly = 1;
01199 $htva->value = 0;
01200 $array[$i]['htva'] = $htva->input();
01201
01202 if ($g_parameter->MY_TVA_USE == 'Y')
01203 $tvac = new INum('tvac_march' . $i);
01204 else
01205 $tvac = new IHidden('tvac_march' . $i);
01206
01207 $tvac->readOnly = 1;
01208 $tvac->value = 0;
01209 $array[$i]['tvac'] = $tvac->input();
01210
01211 if ($g_parameter->MY_UPDLAB == 'Y') {
01212 $Span = new IText("e_march" . $i . "_label");
01213
01214 $Span->css_size = "100%";
01215 } else {
01216 $Span = new ISpan("e_march" . $i . "_label");
01217 }
01218 $Span->value = $march_label;
01219 $Span->setReadOnly(false);
01220
01221
01222 $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", $march_label);
01223
01224 $Price = new INum();
01225 $Price->setReadOnly(false);
01226 $Price->size = 9;
01227 $Price->javascript = "onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
01228 $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", $march_price);
01229 $array[$i]['tva'] = '';
01230 $array[$i]['amount_tva'] = '';
01231
01232 if ($flag_tva == 'Y') {
01233
01234
01235 $Tva = new ITva_Popup($this->db);
01236 $Tva->in_table = true;
01237 $Tva->set_attribute('compute', $i);
01238
01239 $Tva->js = 'onblur="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
01240 $Tva->value = $march_tva_id;
01241 $array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
01242
01243
01244 $wTva_amount = new INum();
01245 $wTva_amount->readOnly = false;
01246 $wTva_amount->size = 6;
01247 $wTva_amount->javascript = "onBlur='format_number(this);compute_ledger($i)'";
01248 $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i . "_tva_amount", $march_tva_amount);
01249 }
01250
01251
01252 $quant = (isset(${"e_quant$i"})) ? ${"e_quant$i"} : "1"
01253 ;
01254 $Quantity = new INum();
01255 $Quantity->setReadOnly(false);
01256 $Quantity->size = 8;
01257 $Quantity->javascript = "onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
01258 $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
01259 }
01260 $f_type = _('Client');
01261
01262
01263 ob_start();
01264 require_once('template/form_ledger_detail.php');
01265 $r.=ob_get_contents();
01266 ob_end_clean();
01267
01268
01269
01270
01271 $r.=HtmlInput::hidden('jrn_type', 'VEN');
01272
01273 $r.=HtmlInput::button('add_item', _('Ajout article'), ' onClick="ledger_add_row()"');
01274 $r.= create_script("$('" . $Date->id . "').focus()");
01275 return $r;
01276 }
01277
01278
01279
01280
01281
01282
01283
01284 function get_detail_sale($p_from,$p_end)
01285 {
01286 global $g_user;
01287
01288 if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
01289
01290
01291 if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
01292
01293
01294 $sql = "select *
01295 from v_detail_sale
01296 where
01297 jr_def_id = $1
01298 and jr_date >= (select p_start from parm_periode where p_id = $2)
01299 and jr_date <= (select p_end from parm_periode where p_id = $3) "
01300 .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
01301 $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
01302 return $ret;
01303 }
01304
01305
01306
01307 static function test_me($p_string = '') {
01308 $cn = new Database(dossier::id());
01309 $a = new Acc_Ledger_Sold($cn, 2);
01310 echo $a->input();
01311 }
01312
01313 }
01314