From 050a4770d3aa7bb386971c8904bb04329ced3841 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 6 Oct 2020 10:04:15 +0200 Subject: [PATCH 1/3] WIP NEW Add clone functionality on miscellaneous payment --- .../bank/class/paymentvarious.class.php | 19 +++++ htdocs/compta/bank/various_payment/card.php | 69 ++++++++++++++++++- htdocs/langs/en_US/banks.lang | 1 + 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php index 14466915d76..712fb3d8113 100644 --- a/htdocs/compta/bank/class/paymentvarious.class.php +++ b/htdocs/compta/bank/class/paymentvarious.class.php @@ -263,6 +263,7 @@ class PaymentVarious extends CommonObject $this->subledger_account = $obj->subledger_account; $this->accountancy_code = $obj->accountancy_code; $this->fk_project = $obj->fk_project; + $this->accountid = 1; // to clone $this->fk_bank = $obj->fk_bank; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_modif = $obj->fk_user_modif; @@ -338,6 +339,24 @@ class PaymentVarious extends CommonObject $this->fk_user_modif = ''; } + /** + * Check if a miscellaneous payment can be created into database + * + * @return boolean True or false + */ + public function check() + { + $newamount = price2num($this->amount, 'MT'); + + // Validation parametres + if (!$newamount > 0 || empty($this->datep)) + { + return false; + } + + return true; + } + /** * Create in database * diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 371dbaa65e2..67a9590c91d 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -41,8 +41,9 @@ $langs->loadLangs(array("compta", "banks", "bills", "users", "accountancy", "cat // Get parameters $id = GETPOST('id', 'int'); -$action = GETPOST('action', 'alpha'); -$cancel = GETPOST('cancel', 'aZ09'); +$action = GETPOST('action', 'alpha'); +$confirm = GETPOST('confirm'); +$cancel = GETPOST('cancel', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); $accountid = GETPOST("accountid") > 0 ? GETPOST("accountid", "int") : 0; @@ -225,6 +226,53 @@ if (empty($reshook)) } } +// Action clone object +if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; } + +if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier)) +{ + $db->begin(); + + $originalId = $id; + + $object->fetch($id); + + if ($object->id > 0) + { + $object->id = $object->ref = null; + + if (GETPOST('clone_label', 'alphanohtml')) { + $object->label = GETPOST('clone_label', 'alphanohtml'); + } else { + $object->label = $langs->trans("CopyOf").' '.$object->label; + } + + $newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int')); + if ($newdatepayment) $object->datep = $newdatepayment; + + if ($object->check()) + { + $id = $object->create($user); + if ($id > 0) + { + $db->commit(); + $db->close(); + + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } else { + $id = $originalId; + $db->rollback(); + + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } else { + $db->rollback(); + dol_print_error($db, $object->error); + } +} + /* * View @@ -419,6 +467,17 @@ if ($id) $head = various_payment_prepare_head($object); + // Clone confirmation + if ($action === 'clone') + { + $formquestion = array( + array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), + ); + $formquestion[] = array('type' => 'date', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1); + + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 220); + } + dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto); $morehtmlref = '
'; @@ -542,6 +601,12 @@ if ($id) // TODO // Add button modify + // Clone + if ($user->rights->banque->modifier) + { + print '"; + } + // Delete if (empty($object->rappro)) { diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index 3cfa7ad2538..ffe5ee9ca1c 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -168,6 +168,7 @@ ShowVariousPayment=Show miscellaneous payment AddVariousPayment=Add miscellaneous payment VariousPaymentId=Miscellaneous payment ID VariousPaymentLabel=Miscellaneous payment label +ConfirmCloneVariousPayment=Confirm the clone of a miscellaneous payment SEPAMandate=SEPA mandate YourSEPAMandate=Your SEPA mandate FindYourSEPAMandate=This is your SEPA mandate to authorize our company to make direct debit order to your bank. Return it signed (scan of the signed document) or send it by mail to From 503f190fd47e23145d5490153b0200bd8b6802da Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 6 Oct 2020 14:39:10 +0200 Subject: [PATCH 2/3] Fix --- htdocs/compta/bank/class/paymentvarious.class.php | 1 - htdocs/compta/bank/various_payment/card.php | 12 ++++++++++-- htdocs/compta/bank/various_payment/list.php | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php index 712fb3d8113..064f8ac8d41 100644 --- a/htdocs/compta/bank/class/paymentvarious.class.php +++ b/htdocs/compta/bank/class/paymentvarious.class.php @@ -263,7 +263,6 @@ class PaymentVarious extends CommonObject $this->subledger_account = $obj->subledger_account; $this->accountancy_code = $obj->accountancy_code; $this->fk_project = $obj->fk_project; - $this->accountid = 1; // to clone $this->fk_bank = $obj->fk_bank; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_modif = $obj->fk_user_modif; diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 67a9590c91d..62d022c0157 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -248,7 +248,13 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->m } $newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int')); + $newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int')); if ($newdatepayment) $object->datep = $newdatepayment; + if (!empty($newdatevalue)) { + $object->datev = $newdatevalue; + } else { + $object->datev = $newdatepayment; + } if ($object->check()) { @@ -473,9 +479,11 @@ if ($id) $formquestion = array( array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), ); - $formquestion[] = array('type' => 'date', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1); + $formquestion[] = array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1); + $formquestion[] = array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1); + $formquestion[] = array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($accountid, "accountid", 0, '', 1)); - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 220); + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 300); } dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto); diff --git a/htdocs/compta/bank/various_payment/list.php b/htdocs/compta/bank/various_payment/list.php index 54216f06358..2fb2c56fc46 100644 --- a/htdocs/compta/bank/various_payment/list.php +++ b/htdocs/compta/bank/various_payment/list.php @@ -490,9 +490,9 @@ if ($result) print $accountstatic->getNomUrl(1); } else { print ' '; - print ''; - if (!$i) $totalarray['nbfield']++; } + print ''; + if (!$i) $totalarray['nbfield']++; } // Bank entry From 973502bb1e6ac99ee162dc73851824b683cfb71e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 7 Oct 2020 09:36:29 +0200 Subject: [PATCH 3/3] Fix --- htdocs/compta/bank/class/paymentvarious.class.php | 4 ++-- htdocs/compta/bank/various_payment/card.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/bank/class/paymentvarious.class.php b/htdocs/compta/bank/class/paymentvarious.class.php index 064f8ac8d41..157a7096eb8 100644 --- a/htdocs/compta/bank/class/paymentvarious.class.php +++ b/htdocs/compta/bank/class/paymentvarious.class.php @@ -347,8 +347,8 @@ class PaymentVarious extends CommonObject { $newamount = price2num($this->amount, 'MT'); - // Validation parametres - if (!$newamount > 0 || empty($this->datep)) + // Validation of parameters + if (!($newamount) > 0 || empty($this->datep)) { return false; } diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 62d022c0157..56843c9032f 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -272,6 +272,11 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->m setEventMessages($object->error, $object->errors, 'errors'); } + } else { + $id = $originalId; + $db->rollback(); + + setEventMessages($object->error, $object->errors, 'errors'); } } else { $db->rollback();