prepare invoice selection and calculation
This commit is contained in:
parent
39228f6221
commit
f91fe41f45
@ -913,7 +913,7 @@ if (empty($reshook))
|
||||
// Proprietes particulieres a facture avoir
|
||||
$object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '';
|
||||
$object->type = Facture::TYPE_CREDIT_NOTE;
|
||||
|
||||
|
||||
$id = $object->create($user);
|
||||
|
||||
if (GETPOST('invoiceAvoirWithLines', 'int')==1 && $id>0)
|
||||
@ -922,6 +922,11 @@ if (empty($reshook))
|
||||
if ($facture_source->fetch($object->fk_facture_source)>0)
|
||||
{
|
||||
$fk_parent_line = 0;
|
||||
if ($facture_source->type == Facture::TYPE_SITUATION)
|
||||
{
|
||||
$facture_source->fetchPreviousNextSituationInvoice();
|
||||
}
|
||||
|
||||
|
||||
foreach($facture_source->lines as $line)
|
||||
{
|
||||
@ -935,10 +940,51 @@ if (empty($reshook))
|
||||
if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
|
||||
$fk_parent_line = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if($facture_source->type == Facture::TYPE_SITUATION)
|
||||
{
|
||||
if(!empty($facture_source->tab_previous_situation_invoice))
|
||||
{
|
||||
$lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
|
||||
$maxPrevSituationPercent = 0;
|
||||
foreach($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine)
|
||||
{
|
||||
if($prevLine->id == $line->fk_prev_id)
|
||||
{
|
||||
$maxPrevSituationPercent = max($maxPrevSituationPercent,$prevLine->situation_percent);
|
||||
|
||||
//$line->subprice = $line->subprice - $prevLine->subprice;
|
||||
$line->total_ht = $line->total_ht - $prevLine->total_ht;
|
||||
$line->total_tva = $line->total_tva - $prevLine->total_tva;
|
||||
$line->total_ttc = $line->total_ttc - $prevLine->total_ttc;
|
||||
$line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1;
|
||||
$line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2;
|
||||
|
||||
$line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice;
|
||||
$line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht;
|
||||
$line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva;
|
||||
$line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// prorata
|
||||
$line->qty = $line->qty * $maxPrevSituationPercent / 100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $sql.= ", situation_cycle_ref, situation_counter, situation_final";
|
||||
// situation_percent
|
||||
}
|
||||
|
||||
$line->fk_facture = $object->id;
|
||||
$line->fk_parent_line = $fk_parent_line;
|
||||
|
||||
|
||||
$line->subprice = -$line->subprice; // invert price for object
|
||||
$line->pa_ht = $line->pa_ht; // we choosed to have buy/cost price always positive, so no revert of sign here
|
||||
$line->total_ht = -$line->total_ht;
|
||||
@ -946,7 +992,7 @@ if (empty($reshook))
|
||||
$line->total_ttc = -$line->total_ttc;
|
||||
$line->total_localtax1 = -$line->total_localtax1;
|
||||
$line->total_localtax2 = -$line->total_localtax2;
|
||||
|
||||
|
||||
$line->multicurrency_subprice = -$line->multicurrency_subprice;
|
||||
$line->multicurrency_total_ht = -$line->multicurrency_total_ht;
|
||||
$line->multicurrency_total_tva = -$line->multicurrency_total_tva;
|
||||
|
||||
@ -3495,6 +3495,18 @@ class Facture extends CommonInvoice
|
||||
|
||||
$return = array();
|
||||
|
||||
|
||||
// Select the last situation invoice
|
||||
$sqlSit = 'SELECT MAX(fs.rowid)';
|
||||
$sqlSit.= " FROM ".MAIN_DB_PREFIX."facture as fs";
|
||||
$sqlSit.= " WHERE fs.entity = ".$conf->entity;
|
||||
$sqlSit.= " AND fs.type != ".self::TYPE_SITUATION;
|
||||
$sqlSit.= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
|
||||
$sqlSit.= " GROUP BY fs.situation_cycle_ref";
|
||||
$sqlSit.= " ORDER BY fs.situation_counter";
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT f.rowid as rowid, f.facnumber, f.fk_statut, f.type, f.paye, pf.fk_paiement";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
|
||||
@ -3506,6 +3518,7 @@ class Facture extends CommonInvoice
|
||||
// $sql.= " OR f.close_code IS NOT NULL)"; // Classee payee partiellement
|
||||
$sql.= " AND ff.type IS NULL"; // Renvoi vrai si pas facture de remplacement
|
||||
$sql.= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir
|
||||
//$sql.= " AND ( f.type != ".self::TYPE_SITUATION . " OR f.rowid IN (".$sqlSit.") )"; // Type non 5 si facture non avoir
|
||||
if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid;
|
||||
$sql.= " ORDER BY f.facnumber";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user