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