From 236a61ab55a08a471174ff5aab73357a2ce9d644 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Wed, 17 Oct 2018 11:56:32 +0200 Subject: [PATCH] new manage correctly create bills on reception --- .../fourn/class/fournisseur.facture.class.php | 5 +++- htdocs/langs/fr_FR/receptions.lang | 2 +- htdocs/reception/class/reception.class.php | 4 ++-- htdocs/reception/create-table.php | 15 +++++++++--- htdocs/reception/list.php | 24 ++++++++++++------- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 7a17de63926..10c4b5585de 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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 int $origin_id id origin document * @param double $pu_ht_devise Amount in currency + * @param string $ref_supplier Supplier ref * @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. */ - 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); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -2521,6 +2522,8 @@ class SupplierInvoiceLine extends CommonObjectLine $error++; } } + + $this->deleteObjectLinked(); if (!$error) { // Supprime ligne diff --git a/htdocs/langs/fr_FR/receptions.lang b/htdocs/langs/fr_FR/receptions.lang index 349abbd711e..3dab5a0500e 100644 --- a/htdocs/langs/fr_FR/receptions.lang +++ b/htdocs/langs/fr_FR/receptions.lang @@ -79,4 +79,4 @@ ClassifyUnbilled=Classer non facturé DateInvoice=Date de facturation CreateOneBillByThird=Créer une facture par tiers (sinon une par réception) ValidateInvoices=Factures validées - +StatusMustBeValidate=La réception %s doit être au statut 'Validée' diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index a0a5c216781..66fc2151aa0 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -173,7 +173,7 @@ class Reception extends CommonObject * Create reception en base * * @param User $user Objet du user qui cree - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 si erreur, id reception creee si ok */ function create($user, $notrigger=0) @@ -1471,7 +1471,7 @@ class Reception extends CommonObject $resql=$this->db->query($sql); 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) { $order = new CommandeFournisseur($this->db); diff --git a/htdocs/reception/create-table.php b/htdocs/reception/create-table.php index df5512144d8..5bf00a34abc 100644 --- a/htdocs/reception/create-table.php +++ b/htdocs/reception/create-table.php @@ -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;'; -$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); 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;"; -$db->query($sql); +$resql = $db->query($sql); +if(empty($resql)){ + var_dump($db->error); +} diff --git a/htdocs/reception/list.php b/htdocs/reception/list.php index 991349dda08..14c2f65cd57 100644 --- a/htdocs/reception/list.php +++ b/htdocs/reception/list.php @@ -166,22 +166,25 @@ if (empty($reshook)) $nb_bills_created = 0; $db->begin(); - + $errors =array(); foreach($receptions as $id_reception) { $rcp = new Reception($db); - if ($rcp->fetch($id_reception) <= 0) continue; - if($rcp->statut != 1) continue; // On ne facture que les réceptions validées - $rcp->fetch_thirdparty(); - + // On ne facture que les réceptions validées + if ($rcp->fetch($id_reception) <= 0 || $rcp->statut != 1){ + $errors[]=$langs->trans('StatusMustBeValidate',$rcp->ref); + $error++; + continue; + } + $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. else { $object->socid = $rcp->socid; $object->type = FactureFournisseur::TYPE_STANDARD; - $object->cond_reglement_id = $rcp->thirdparty->cond_reglement_id; - $object->mode_reglement_id = $rcp->thirdparty->mode_reglement_id; + $object->cond_reglement_id = $rcp->thirdparty->cond_reglement_supplier_id; + $object->mode_reglement_id = $rcp->thirdparty->mode_reglement_supplier_id; $object->fk_project = $rcp->fk_project; $object->ref_supplier = $rcp->ref_supplier; @@ -201,6 +204,7 @@ if (empty($reshook)) $nb_bills_created++; $object->id = $res; }else { + $errors[]=$object->error; $error++; } } @@ -212,6 +216,7 @@ if (empty($reshook)) if ($res==0) { + $errors[]=$object->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) { @@ -361,11 +366,12 @@ if (empty($reshook)) } else { + $db->rollback(); $action='create'; $_GET["origin"]=$_POST["origin"]; $_GET["originid"]=$_POST["originid"]; - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $errors, 'errors'); $error++; } }