diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 687df742d2f..c4b8be07e9e 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -152,6 +152,11 @@ if ($_POST["action"] == 'set_enable_editdelete') dolibarr_set_const($db, "FACTURE_ENABLE_EDITDELETE",$_POST["enable_editdelete"]); } +if ($_POST["action"] == 'set_use_bill_contact_as_recipient') +{ + dolibarr_set_const($db, "FACTURE_USE_BILL_CONTACT_AS_RECIPIENT",$_POST["use_bill_contact_as_recipient"]); +} + if ($_POST["action"] == 'update' || $_POST["action"] == 'add') { if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'')); @@ -545,6 +550,19 @@ print '' print "\n"; print ''; +// Active la possibilité d'éditer/supprimer une facture validée sans paiement +$var=! $var; +print '
'; + print ''; diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 62b874681c2..c71e2b7a121 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -323,55 +323,65 @@ class CommonObject /** * \brief Charge le contact d'id $id dans this->contact * \param contactid Id du contact + * \return int <0 if KO, >0 if OK */ function fetch_contact($contactid) { - $contact = new Contact($this->db); - $contact->fetch($contactid); - $this->contact = $contact; - } + $contact = new Contact($this->db); + $result=$contact->fetch($contactid); + $this->contact = $contact; + return $result; + } /** * \brief Charge le tiers d'id $this->socid dans this->client + * \return int <0 if KO, >0 if OK */ function fetch_client() { $client = new Societe($this->db); - $client->fetch($this->socid); + $result=$client->fetch($this->socid); $this->client = $client; + return $result; } /** * \brief Charge le projet d'id $this->projet_id dans this->projet + * \return int <0 if KO, >0 if OK */ function fetch_projet() { $projet = new Project($this->db); - $projet->fetch($this->projet_id); + $result=$projet->fetch($this->projet_id); $this->projet = $projet; + return $result; } /** * \brief Charge le user d'id userid dans this->user * \param userid Id du contact + * \return int <0 if KO, >0 if OK */ function fetch_user($userid) { - $user = new User($this->db, $userid); - $user->fetch(); - $this->user = $user; + $user = new User($this->db, $userid); + $result=$user->fetch(); + $this->user = $user; + return $result; } - /** - * \brief Charge l'adresse de livraison d'id $this->adresse_livraison_id dans this->deliveryaddress - * \param userid Id du contact - */ + /** + * \brief Charge l'adresse de livraison d'id $this->adresse_livraison_id dans this->deliveryaddress + * \param userid Id du contact + * \return int <0 if KO, >0 if OK + */ function fetch_adresse_livraison($deliveryaddressid) - { - $address = new Societe($this->db); - $address->fetch_adresse_livraison($deliveryaddressid); - $this->deliveryaddress = $address; - } + { + $address = new Societe($this->db); + $result=$address->fetch_adresse_livraison($deliveryaddressid); + $this->deliveryaddress = $address; + return $result; + } /** * \brief Retourne la liste déroulante des sociétés diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php index 80a7de9dffc..9aadbbb9bd0 100644 --- a/htdocs/includes/modules/facture/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php @@ -978,12 +978,12 @@ class pdf_crabe extends ModelePDFFactures // Nom emetteur $pdf->SetTextColor(0,0,60); $pdf->SetFont('Arial','B',11); - if (defined("FAC_PDF_SOCIETE_NOM") && FAC_PDF_SOCIETE_NOM) $pdf->MultiCell(80, 4, FAC_PDF_SOCIETE_NOM, 0, 'L'); + if (defined("FAC_PDF_SOCIETE_NOM") && FAC_PDF_SOCIETE_NOM) $pdf->MultiCell(80, 4, FAC_PDF_SOCIETE_NOM, 0, 'L'); // deprecated else $pdf->MultiCell(80, 4, $this->emetteur->nom, 0, 'L'); // Caractéristiques emetteur $carac_emetteur = ''; - if (defined("FAC_PDF_ADRESSE") && FAC_PDF_ADRESSE) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).FAC_PDF_ADRESSE; + if (defined("FAC_PDF_ADRESSE") && FAC_PDF_ADRESSE) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).FAC_PDF_ADRESSE; // deprecated else { $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$this->emetteur->adresse; $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$this->emetteur->cp.' '.$this->emetteur->ville; @@ -1017,22 +1017,37 @@ class pdf_crabe extends ModelePDFFactures // Cadre client destinataire $pdf->rect(100, $posy, 100, $hautcadre); - // Nom client - $pdf->SetXY(102,$posy+3); - $pdf->SetFont('Arial','B',11); - $pdf->MultiCell(106,4, $object->client->nom, 0, 'L'); + // If invoice contact defined on invoice, we use it + $receiver=0; + if ($conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT) + { + $arrayidcontact=$object->getIdContact('external','BILLING'); + if (sizeof($arrayidcontact) > 0) + { + $idcontact=$arrayidcontact[0]; + $result=$object->fetch_contact($idcontact); + if ($result > 0) $receiver=$object->contact; + $receiver=$object->contact; + } + } + if (! $receiver) $receiver=$object->client; - // Caractéristiques client - $carac_client=$object->client->adresse; - $carac_client.="\n".$object->client->cp . " " . $object->client->ville."\n"; - if ($this->emetteur->pays_code != $object->client->pays_code) - { - $carac_client.=$object->client->pays."\n"; - } - if ($object->client->tva_intra) $carac_client.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$object->client->tva_intra; - $pdf->SetFont('Arial','',9); - $pdf->SetXY(102,$posy+8); - $pdf->MultiCell(86,4, $carac_client); + // Nom client + $pdf->SetXY(102,$posy+3); + $pdf->SetFont('Arial','B',11); + $pdf->MultiCell(106,4, $receiver->nom, 0, 'L'); + + // Caractéristiques client + $carac_client=$receiver->adresse; + $carac_client.="\n".$receiver->cp . " " . $receiver->ville."\n"; + if ($this->emetteur->pays_code != $receiver->pays_code) + { + $carac_client.=$receiver->pays."\n"; + } + if ($receiver->tva_intra) $carac_client.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$receiver->tva_intra; + $pdf->SetFont('Arial','',9); + $pdf->SetXY(102,$posy+8); + $pdf->MultiCell(86,4, $carac_client); } } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index d5814978973..11fa1531324 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -288,6 +288,7 @@ ChequesArea=Cheques deposits area ChequeDeposits=Cheques deposits Cheques=Cheques CreditNoteConvertedIntoDiscount=This credit note has been converted into %s +UsBillingContactAsIncoiveRecipientIfExist=Use customer billing contact address instead of third party address as recipient for invoices # oursin PDF model Of=du diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index e573173b19b..e9043388f1f 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -288,6 +288,7 @@ ChequesArea=Espace remises de ch ChequeDeposits=Dépots de chèques Cheques=Chèques CreditNoteConvertedIntoDiscount=Cet avoir a été converti en %s +UsBillingContactAsIncoiveRecipientIfExist=Utiliser l'adresse du contact facturation client de la facture plutot que l'adresse du tiers comme destinataire des factures # oursin PDF model Of=du