new manage correctly create bills on reception

This commit is contained in:
atm-quentin 2018-10-17 11:56:32 +02:00
parent e3a0a5e4f5
commit 236a61ab55
5 changed files with 34 additions and 16 deletions

View File

@ -1363,11 +1363,12 @@ class FactureFournisseur extends CommonInvoice
* @param string $fk_unit Code of the unit to use. Null to use the default one * @param string $fk_unit Code of the unit to use. Null to use the default one
* @param int $origin_id id origin document * @param int $origin_id id origin document
* @param double $pu_ht_devise Amount in currency * @param double $pu_ht_devise Amount in currency
* @param string $ref_supplier Supplier ref
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO
* *
* FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order. * FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order.
*/ */
public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null, $origin_id=0, $pu_ht_devise=0) public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null, $origin_id=0, $pu_ht_devise=0,$ref_supplier='')
{ {
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG); dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@ -2522,6 +2523,8 @@ class SupplierInvoiceLine extends CommonObjectLine
} }
} }
$this->deleteObjectLinked();
if (!$error) { if (!$error) {
// Supprime ligne // Supprime ligne
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det '; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det ';

View File

@ -79,4 +79,4 @@ ClassifyUnbilled=Classer non facturé
DateInvoice=Date de facturation DateInvoice=Date de facturation
CreateOneBillByThird=Créer une facture par tiers (sinon une par réception) CreateOneBillByThird=Créer une facture par tiers (sinon une par réception)
ValidateInvoices=Factures validées ValidateInvoices=Factures validées
StatusMustBeValidate=La réception %s doit être au statut 'Validée'

View File

@ -1471,7 +1471,7 @@ class Reception extends CommonObject
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
// Set order billed if 100% of order is shipped (qty in reception lines match qty in order lines) // Set order billed if 100% of order is received (qty in reception lines match qty in order lines)
if ($this->origin == 'order_supplier' && $this->origin_id > 0) if ($this->origin == 'order_supplier' && $this->origin_id > 0)
{ {
$order = new CommandeFournisseur($this->db); $order = new CommandeFournisseur($this->db);

View File

@ -39,15 +39,24 @@ $dir = DOL_DOCUMENT_ROOT."/install/mysql/tables/";
$sql='ALTER TABLE '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch ADD COLUMN fk_reception integer DEFAULT NULL;'; $sql='ALTER TABLE '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch ADD COLUMN fk_reception integer DEFAULT NULL;';
$db->query($sql); $resql = $db->query($sql);
if(empty($resql)){
var_dump($db->error);
}
$sql=" insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('RECEPTION_VALIDATE','Reception validated','Executed when a reception is validated','reception',22); $sql=" insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('RECEPTION_VALIDATE','Reception validated','Executed when a reception is validated','reception',22);
insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('RECEPTION_SENTBYMAIL','Reception sent by mail','Executed when a reception is sent by mail','reception',22);"; insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('RECEPTION_SENTBYMAIL','Reception sent by mail','Executed when a reception is sent by mail','reception',22);";
$db->query($sql); $resql = $db->query($sql);
if(empty($resql)){
var_dump($db->error);
}
$sql=" ALTER TABLE ".MAIN_DB_PREFIX."commande_fournisseur_dispatch CHANGE comment comment TEXT;"; $sql=" ALTER TABLE ".MAIN_DB_PREFIX."commande_fournisseur_dispatch CHANGE comment comment TEXT;";
$db->query($sql); $resql = $db->query($sql);
if(empty($resql)){
var_dump($db->error);
}

View File

@ -166,13 +166,16 @@ if (empty($reshook))
$nb_bills_created = 0; $nb_bills_created = 0;
$db->begin(); $db->begin();
$errors =array();
foreach($receptions as $id_reception) foreach($receptions as $id_reception)
{ {
$rcp = new Reception($db); $rcp = new Reception($db);
if ($rcp->fetch($id_reception) <= 0) continue; // On ne facture que les réceptions validées
if($rcp->statut != 1) continue; // On ne facture que les réceptions validées if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1){
$rcp->fetch_thirdparty(); $errors[]=$langs->trans('StatusMustBeValidate',$rcp->ref);
$error++;
continue;
}
$object = new FactureFournisseur($db); $object = new FactureFournisseur($db);
if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) $object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception. if (!empty($createbills_onebythird) && !empty($TFactThird[$rcp->socid])) $object = $TFactThird[$rcp->socid]; // If option "one bill per third" is set, we use already created reception.
@ -180,8 +183,8 @@ if (empty($reshook))
$object->socid = $rcp->socid; $object->socid = $rcp->socid;
$object->type = FactureFournisseur::TYPE_STANDARD; $object->type = FactureFournisseur::TYPE_STANDARD;
$object->cond_reglement_id = $rcp->thirdparty->cond_reglement_id; $object->cond_reglement_id = $rcp->thirdparty->cond_reglement_supplier_id;
$object->mode_reglement_id = $rcp->thirdparty->mode_reglement_id; $object->mode_reglement_id = $rcp->thirdparty->mode_reglement_supplier_id;
$object->fk_project = $rcp->fk_project; $object->fk_project = $rcp->fk_project;
$object->ref_supplier = $rcp->ref_supplier; $object->ref_supplier = $rcp->ref_supplier;
@ -201,6 +204,7 @@ if (empty($reshook))
$nb_bills_created++; $nb_bills_created++;
$object->id = $res; $object->id = $res;
}else { }else {
$errors[]=$object->error;
$error++; $error++;
} }
} }
@ -212,6 +216,7 @@ if (empty($reshook))
if ($res==0) if ($res==0)
{ {
$errors[]=$object->error;
$error++; $error++;
} }
} }
@ -297,7 +302,7 @@ if (empty($reshook))
); );
$rcp->add_object_linked('invoice_supplierdet',$result); $rcp->add_object_linked('facture_fourn_det',$result);
if ($result > 0) if ($result > 0)
{ {
@ -361,11 +366,12 @@ if (empty($reshook))
} }
else else
{ {
$db->rollback(); $db->rollback();
$action='create'; $action='create';
$_GET["origin"]=$_POST["origin"]; $_GET["origin"]=$_POST["origin"];
$_GET["originid"]=$_POST["originid"]; $_GET["originid"]=$_POST["originid"];
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $errors, 'errors');
$error++; $error++;
} }
} }