diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index eb43da88a4b..268463f1e7d 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -207,8 +207,12 @@ if (empty($reshook)) { $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone. We use native clone to keep this->db valid. $objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int')); + $objectutil->socid = $socid; - $result = $objectutil->createFromClone($user, $id); + + $targetThirdPartyVat = GETPOSTISSET('targetThirdPartyVat'); + $result = $objectutil->createFromClone($user, $id, $targetThirdPartyVat); + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result); exit(); @@ -4174,9 +4178,10 @@ if ($action == 'create') { // Create an array for form $formquestion = array( array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company($object->socid, 'socid', '(s.client=1 OR s.client=2 OR s.client=3)', 1)), - array('type' => 'date', 'name' => 'newdate', 'label' => $langs->trans("Date"), 'value' => dol_now()) + array('type' => 'date', 'name' => 'newdate', 'label' => $langs->trans("Date"), 'value' => dol_now()), + array('type' => 'checkbox', 'name' => 'targetThirdPartyVat', 'label' => $langs->trans("targetThirdPartyVat"), 'value' => 0 ), ); - // Ask confirmatio to clone + // Ask confirmation to clone $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneInvoice', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 250); } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ec8e4a93b80..fb6a59ef3da 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1192,7 +1192,7 @@ class Facture extends CommonInvoice * @param int $fromid Id of object to clone * @return int New id of clone */ - public function createFromClone(User $user, $fromid = 0) + public function createFromClone(User $user, $fromid = 0, $targetThirdPartyVat = false) { global $conf, $hookmanager; @@ -1277,6 +1277,14 @@ class Facture extends CommonInvoice $object->lines[$i]->ref_ext = ''; // Do not clone ref_ext } + // we have a different thirdparty selected and we checked $targetThirdPartyVat + if ($objFrom->socid != $object->socid && $targetThirdPartyVat) { + global $mysoc; + + foreach ($object->lines as $line) { + $line->tva_tx = get_default_tva($mysoc, $objsoc, $line->fk_product); + } + } // Create clone $object->context['createfromclone'] = 'createfromclone'; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index b9b4b111b43..4d32f48f862 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -609,4 +609,5 @@ NoPaymentAvailable=No payment available for %s PaymentRegisteredAndInvoiceSetToPaid=Payment registered and invoice %s set to paid SendEmailsRemindersOnInvoiceDueDate=Send reminder by email for unpaid invoices MakePaymentAndClassifyPayed=Record payment -BulkPaymentNotPossibleForInvoice=Bulk payment is not possible for invoice %s (bad type or status) \ No newline at end of file +BulkPaymentNotPossibleForInvoice=Bulk payment is not possible for invoice %s (bad type or status) +targetThirdPartyVat=Modify the VAT rate to use the default rate depending on the new thirdparty