new manage correctly create bills on reception
This commit is contained in:
parent
e3a0a5e4f5
commit
236a61ab55
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user