FIX #16530
This commit is contained in:
parent
30dd4ac6ec
commit
6503c81f47
@ -347,8 +347,8 @@ class FactureRec extends CommonInvoice
|
||||
$error++;
|
||||
} else {
|
||||
$objectline = new FactureLigneRec($this->db);
|
||||
if ($objectline->fetch($result_insert))
|
||||
{
|
||||
$result2 = $objectline->fetch($result_insert);
|
||||
if ($result2 > 0) {
|
||||
// Extrafields
|
||||
if (method_exists($facsrc->lines[$i], 'fetch_optionals')) {
|
||||
$facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->rowid);
|
||||
@ -360,6 +360,9 @@ class FactureRec extends CommonInvoice
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
} elseif ($result2 < 0) {
|
||||
$this->errors[] = $objectline->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -421,6 +424,7 @@ class FactureRec extends CommonInvoice
|
||||
if ($error)
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
} else {
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
@ -516,12 +520,15 @@ class FactureRec extends CommonInvoice
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
|
||||
//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
|
||||
$sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
|
||||
if ($rowid) $sql .= ' AND f.rowid='.$rowid;
|
||||
elseif ($ref) $sql .= " AND f.titre='".$this->db->escape($ref)."'";
|
||||
/* This field are not used for template invoice
|
||||
if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
|
||||
if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'";
|
||||
*/
|
||||
if ($rowid) {
|
||||
$sql .= ' AND f.rowid='.((int) $rowid);
|
||||
} elseif ($ref) {
|
||||
$sql .= " AND f.titre='".$this->db->escape($ref)."'";
|
||||
// This field are not used for template invoice
|
||||
//} elseif ($ref_ext) { $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'"; }
|
||||
} else {
|
||||
$sql .= ' AND f.rowid = 0';
|
||||
}
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
@ -651,11 +658,11 @@ class FactureRec extends CommonInvoice
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
|
||||
$sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
|
||||
$sql .= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
|
||||
$sql .= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price, l.buy_price_ht as pa_ht,';
|
||||
//$sql.= ' l.situation_percent, l.fk_prev_id,';
|
||||
//$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,';
|
||||
$sql .= ' l.rang, l.special_code,';
|
||||
//$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
|
||||
//$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price, l.buy_price_ht as pa_ht,';
|
||||
$sql .= ' l.fk_unit, l.fk_contract_line,';
|
||||
$sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
|
||||
$sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
|
||||
@ -706,10 +713,16 @@ class FactureRec extends CommonInvoice
|
||||
$line->total_ht = $objp->total_ht;
|
||||
$line->total_tva = $objp->total_tva;
|
||||
$line->total_ttc = $objp->total_ttc;
|
||||
|
||||
//$line->code_ventilation = $objp->fk_code_ventilation;
|
||||
$line->fk_fournprice = $objp->fk_fournprice;
|
||||
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
|
||||
$line->pa_ht = $marginInfos[0];
|
||||
|
||||
$line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
|
||||
$line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility
|
||||
|
||||
$marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
|
||||
|
||||
$line->buyprice = $marginInfos[0];
|
||||
$line->pa_ht = $marginInfos[0]; // For backward compatibility
|
||||
$line->marge_tx = $marginInfos[1];
|
||||
$line->marque_tx = $marginInfos[2];
|
||||
$line->rang = $objp->rang;
|
||||
@ -1971,6 +1984,10 @@ class FactureLigneRec extends CommonInvoiceLine
|
||||
$sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
|
||||
$sql .= ' l.rang, l.special_code,';
|
||||
$sql .= ' l.fk_unit, l.fk_contract_line,';
|
||||
$sql .= ' l.import_key, l.fk_multicurrency,';
|
||||
$sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
|
||||
$sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,';
|
||||
$sql .= ' l.fk_user_author, l.fk_user_modif,';
|
||||
$sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
|
||||
@ -2018,7 +2035,17 @@ class FactureLigneRec extends CommonInvoiceLine
|
||||
$this->special_code = $objp->special_code;
|
||||
$this->fk_unit = $objp->fk_unit;
|
||||
$this->fk_contract_line = $objp->fk_contract_line;
|
||||
|
||||
$this->import_key = $objp->import_key;
|
||||
$this->fk_multicurrency = $objp->fk_multicurrency;
|
||||
$this->multicurrency_code = $objp->multicurrency_code;
|
||||
$this->multicurrency_subprice = $objp->multicurrency_subprice;
|
||||
$this->multicurrency_total_ht = $objp->multicurrency_total_ht;
|
||||
$this->multicurrency_total_tva = $objp->multicurrency_total_tva;
|
||||
$this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
|
||||
$this->buy_price_ht = $objp->buy_price_ht;
|
||||
$this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
|
||||
$this->fk_user_author = $objp->fk_user_author;
|
||||
$this->fk_user_modif = $objp->fk_user_modif;
|
||||
|
||||
$this->db->free($result);
|
||||
return 1;
|
||||
|
||||
@ -915,8 +915,9 @@ class Facture extends CommonInvoice
|
||||
$localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
|
||||
$localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
|
||||
|
||||
$fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ?null:$_facrec->lines[$i]->fk_product_fournisseur_price;
|
||||
$fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ? null : $_facrec->lines[$i]->fk_product_fournisseur_price;
|
||||
$buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
|
||||
|
||||
// If buyprice not defined from template invoice, we try to guess the best value
|
||||
if (!$buyprice && $_facrec->lines[$i]->fk_product > 0)
|
||||
{
|
||||
@ -984,6 +985,7 @@ class Facture extends CommonInvoice
|
||||
if (!$error)
|
||||
{
|
||||
$result = $this->update_price(1);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$action = 'create';
|
||||
|
||||
@ -128,7 +128,7 @@ class FactureRecTest extends PHPUnit\Framework\TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* testFactureCreate
|
||||
* testFactureRecCreate
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@ -142,19 +142,44 @@ class FactureRecTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
$localobjectinv=new Facture($this->savdb);
|
||||
$localobjectinv->initAsSpecimen();
|
||||
$localobjectinv->create($user);
|
||||
$result = $localobjectinv->create($user);
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
|
||||
$localobject=new FactureRec($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$result=$localobject->create($user, $localobjectinv->id);
|
||||
$result = $localobject->create($user, $localobjectinv->id);
|
||||
|
||||
$this->assertLessThan($result, 0);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result, 'Create recurring invoice from common invoice');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testFactureRecFetch
|
||||
*
|
||||
* @param int $id Id of created recuriing invoice
|
||||
* @return int
|
||||
*
|
||||
* @depends testFactureRecCreate
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testFactureRecFetch($id)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new FactureRec($this->savdb);
|
||||
$result = $localobject->fetch($id);
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertGreaterThan(0, $result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user