267 $jrn = $_POST[
'p_jrn'];
268 $ledger =
new Acc_Ledger($cn, $jrn);
273 $ledger =
new Acc_Ledger_Purchase($cn, $jrn);
278 $ledger =
new Acc_Ledger_Sold($cn, $jrn);
283 die(
'Erreur ce type journal n\' est pas encore supporté');
288 $array = $cn->get_array(
"select
290 from impdol.operation_tmp
291 where i_id=$1 and o_result='T'
292 order by o_doli asc", array($this->impid));
298 for ($i = 0; $i <
$nb_row; $i++)
303 $adetail = $cn->get_array(
"select o_id from impdol.operation_tmp where o_doli=$1 and i_id=$2 and o_type='S'", array(
$array[$i][
'o_doli'], $this->impid));
304 $atiers = $cn->get_array(
"select o_id from impdol.operation_tmp where o_doli=$1 and i_id=$2 and o_type='T'", array(
$array[$i][
'o_doli'], $this->impid));
305 if (count($atiers) > 1)
307 echo
"Plusieurs clients pour l' opération, code " .
$array[$i][
'o_doli'];
310 if (count($atiers) == 0)
312 echo
"Pas de client pour une opération, code " .
$array[$i][
'o_doli'];
316 $oper_tiers =
new Impdol_Operation_Tmp_Sql($atiers[0][
'o_id']);
317 $nb_detail = count($adetail);
318 $sum = 0; $sum_side=0;
319 $grpt = $cn->get_value(
"select nextval('s_grpt');");
320 $internal =
$ledger->compute_internal_code($grpt);
324 for ($e = 0; $e < $nb_detail; $e++)
327 $oper =
new Impdol_Operation_Tmp_Sql($adetail[$e][
'o_id']);
328 $oper->from_array(
$array[$i]);
329 $date = format_date($oper->getp(
"date"),
"YYYY-MM-DD",
"DD.MM.YYYY");
330 $oper->setp(
"date",
$date);
331 $jrnx =
new Acc_Operation($cn);
333 $amount_tva = $oper->getp(
"amount_vat");
334 $amount_tvac = $oper->getp(
"amount_total");
335 $jrnx->amount = bcsub($amount_tvac, $amount_tva);
336 $save_amount=$jrnx->amount;
337 $jrnx->poste = $oper->getp(
'poste');
339 $jrnx->type = $oth_side;
341 $jrnx->user = $_SESSION[
'g_user'];
343 $jrnx->qcode = $oper->getp(
"qcode");
344 $jrnx->desc = mb_substr($oper->getp(
"desc"),0,80,
'UTF8');
345 $id = $jrnx->insert_jrnx();
348 $transfer->setp(
"j_id", $id);
349 $transfer->setp(
"o_id", $oper->getp(
"id"));
352 $tva_id = $oper->getp(
"tva_id");
360 $sql =
"insert into quant_purchase(qp_internal,j_id,qp_fiche,qp_quantite,qp_price,qp_vat,qp_vat_code,qp_supplier)
361 values($1,$2,$3,$4,$5,$6,$7,$8)";
362 $cn->exec_sql(
$sql, array(null, $id, $oper->getp(
"fiche"), $oper->getp(
"number_unit"), $save_amount, $amount_tva,
$tva_id, $oper_tiers->getp(
"fiche")));
363 $sum_side = ($save_amount > 0) ? bcadd($sum_side, $amount_tvac):$sum_side;
366 $cn->exec_sql(
"insert into quant_sold
367 (qs_internal,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client,j_id,qs_vat_sided,qs_valid)
369 ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null,
370 $oper->getp(
"fiche"),
371 $oper->getp(
"number_unit"),
375 $oper_tiers->getp(
'fiche'),
381 $sum_side = ($save_amount > 0) ? bcadd($sum_side, $amount_tvac):$sum_side;
385 $side=($amount_tva > 0)?1:0;
386 if (isset(
$tva[$tva_id][$side]))
394 $sum = bcadd($sum, $amount_tvac);
399 $jtiers =
new Acc_Operation($cn);
400 $jtiers->date =
$date;
401 $jtiers->amount = $sum;
402 $jtiers->poste = $oper_tiers->getp(
'poste');
403 $jtiers->grpt = $grpt;
404 $jtiers->type = $tiers_side;
406 $jtiers->user = $_SESSION[
'g_user'];
407 $jtiers->periode = 0;
408 $jtiers->qcode = $oper_tiers->getp(
"qcode");
409 $jtiers->desc = mb_substr($oper_tiers->getp(
"desc"),0,80,
'UTF8');
410 $jtiers->insert_jrnx();
414 foreach (
$atva as $tvaid=>$tva_value)
417 if (
$tva->load() == -1 ) die (
"Code TVA inconnu $tvaid");
418 $poste =
$tva->get_side($oth_side);
419 $op_tva =
new Acc_Operation($cn);
420 $op_tva->date =
$date;
421 $op_tva->amount = $tva_value;
422 $op_tva->poste = $poste;
423 $op_tva->grpt = $grpt;
424 $op_tva->type = $oth_side;
426 $op_tva->user = $_SESSION[
'g_user'];
427 $op_tva->periode = 0;
428 $op_tva->qcode = null;
429 $op_tva->desc =
$tva->tva_label;
430 $op_tva->insert_jrnx();
434 $acc_jrn =
new Acc_Operation($cn);
435 $acc_jrn->jrn = $jrn;
436 $acc_jrn->amount =abs ($sum_side);
437 $acc_jrn->desc = mb_substr($oper_tiers->getp(
"desc"),0,80,
'UTF8');
438 $acc_jrn->date =
$date;
439 $acc_jrn->grpt = $grpt;
440 $acc_jrn->periode = 0;
441 $acc_jrn->insert_jrn();
442 $cn->exec_sql(
'update jrn set jr_pj_number=$1 where jr_id=$2',array($oper->getp(
'pj'),$acc_jrn->jr_id));
446 $ledger->update_internal_code($internal);
453 $cn->exec_sql(
'update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $grpt));
456 $cn->exec_sql(
'update quant_sold set qs_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $grpt));
464 print_r($e->getTraceAsString());
if(isset($_POST['ftvaadd'])) if(isset($_POST['mod'])) $atva
get data from database
$type
Retrouve le type de row si == 3.
if(isset($_POST['remove'])) $array
if(isset($_POST['save'])) $tva