diff --git a/ChangeLog b/ChangeLog index a0d32f49010..1d1f3a0720d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ NEW: Accountancy - Add specific page to export accounting data rather than the j NEW: Accountancy - Add sub-account balance FPC22 NEW: Accountancy - Manage customer retained warranty FPC21+ NEW: Accountancy - Manage intra-community VAT on supplier invoices - FPC22 +NEW: Can upload a file with drag and drop on purchase invoice, vats, salaries and social contributions NEW: adapt category and product pictures sizes on takepos NEW: Add ability of ODT support to supplier invoices NEW: Add a public virtual card page for each user diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 49e1d8362ed..a9ab57a7037 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -453,9 +453,6 @@ if ($action == 'create') { // View mode if ($id > 0) { - $object = new ChargeSociales($db); - $result = $object->fetch($id); - $formconfirm = ''; if ($result > 0) { diff --git a/htdocs/compta/tva/card.php b/htdocs/compta/tva/card.php index c78b41ba274..d2a34bc8d2c 100644 --- a/htdocs/compta/tva/card.php +++ b/htdocs/compta/tva/card.php @@ -43,9 +43,9 @@ if (isModEnabled('accounting')) { // Load translation files required by the page $langs->loadLangs(array('compta', 'banks', 'bills')); -$id = GETPOST("id", 'int'); +$id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST("action", "aZ09"); +$action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search @@ -80,8 +80,8 @@ if (empty($action) && empty($id) && empty($ref)) { } // Load object -if ($id > 0) { - $object->fetch($id); +if ($id > 0 || $ref) { + $object->fetch($id, $ref); } $permissiontoread = $user->rights->tax->charges->lire; @@ -96,277 +96,282 @@ $socid = GETPOST('socid', 'int'); if ($user->socid) { $socid = $user->socid; } -$result = restrictedArea($user, 'tax', '', 'tva', 'charges'); +$result = restrictedArea($user, 'tax', $object->id, 'tva', 'charges'); /* * Actions */ -$parameters = array(); +$parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } -if ($cancel && !$id) { - header("Location: list.php"); - exit; -} - -if ($action == 'setlib' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -if ($action == 'setdatev' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $object->datev = $datev; - $result = $object->update($user); - if ($result < 0) { - dol_print_error($db, $object->error); +if (empty($reshook)) { + if ($cancel && !$id) { + header("Location: list.php"); + exit; } - $action = ''; -} - -// payment mode -if ($action == 'setmode' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -// Bank account -if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -// Classify paid -if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { - $object->fetch($id); - $result = $object->setPaid($user); -} - -if ($action == 'reopen' && $user->rights->tax->charges->creer) { - $result = $object->fetch($id); - if ($object->paye) { - $result = $object->setUnpaid($user); - if ($result > 0) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit(); - } else { + if ($action == 'setlib' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY'); + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } -} -if ($action == 'add' && !$cancel) { - $error = 0; + if ($action == 'setdatev' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $object->datev = $datev; + $result = $object->update($user); + if ($result < 0) { + dol_print_error($db, $object->error); + } - $object->fk_account = GETPOST("accountid", 'int'); - $object->type_payment = GETPOST("type_payment", 'alphanohtml'); - $object->num_payment = GETPOST("num_payment", 'alphanohtml'); - - $object->datev = $datev; - $object->datep = $datep; - - $amount = price2num(GETPOST("amount", 'alpha')); - if ($refund == 1) { - $amount = -$amount; - } - $object->amount = $amount; - $object->label = GETPOST("label", 'alpha'); - $object->note = GETPOST("note", 'restricthtml'); - $object->note_private = GETPOST("note", 'restricthtml'); - - if (empty($object->datep)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors'); - $error++; - } - if (empty($object->datev)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors'); - $error++; - } - if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors'); - $error++; - } - if (empty($object->amount)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); - $error++; - } - if (!empty($auto_create_payment) && ($object->fk_account <= 0)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors'); - $error++; + $action = ''; } - if (!$error) { - $ret = $object->create($user); - if ($ret < 0) { + // payment mode + if ($action == 'setmode' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Bank account + if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setBankAccount(GETPOST('fk_account', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Classify paid + if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { + $object->fetch($id); + $result = $object->setPaid($user); + } + + if ($action == 'reopen' && $user->rights->tax->charges->creer) { + $result = $object->fetch($id); + if ($object->paye) { + $result = $object->setUnpaid($user); + if ($result > 0) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + if ($action == 'add' && !$cancel) { + $error = 0; + + $object->fk_account = GETPOST("accountid", 'int'); + $object->type_payment = GETPOST("type_payment", 'alphanohtml'); + $object->num_payment = GETPOST("num_payment", 'alphanohtml'); + + $object->datev = $datev; + $object->datep = $datep; + + $amount = price2num(GETPOST("amount", 'alpha')); + if ($refund == 1) { + $amount = -$amount; + } + $object->amount = $amount; + $object->label = GETPOST("label", 'alpha'); + $object->note = GETPOST("note", 'restricthtml'); + $object->note_private = GETPOST("note", 'restricthtml'); + + if (empty($object->datep)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors'); + $error++; + } + if (empty($object->datev)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors'); + $error++; + } + if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors'); + $error++; + } + if (empty($object->amount)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); + $error++; + } + if (!empty($auto_create_payment) && ($object->fk_account <= 0)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors'); $error++; } - // Auto create payment - if (!empty($auto_create_payment) && !$error) { - $db->begin(); + if (!$error) { + $ret = $object->create($user); + if ($ret < 0) { + $error++; + } - // Create a line of payments - $paiement = new PaymentVAT($db); - $paiement->chid = $object->id; - $paiement->datepaye = $datep; - $paiement->amounts = array($object->id=>$amount); // Tableau de montant - $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml'); - $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); - $paiement->note = GETPOST("note", 'restricthtml'); + // Auto create payment + if (!empty($auto_create_payment) && !$error) { + $db->begin(); - if (!$error) { - $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva')); - if ($paymentid < 0) { - $error++; - setEventMessages($paiement->error, null, 'errors'); - $action = 'create'; + // Create a line of payments + $paiement = new PaymentVAT($db); + $paiement->chid = $object->id; + $paiement->datepaye = $datep; + $paiement->amounts = array($object->id=>$amount); // Tableau de montant + $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml'); + $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); + $paiement->note = GETPOST("note", 'restricthtml'); + + if (!$error) { + $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva')); + if ($paymentid < 0) { + $error++; + setEventMessages($paiement->error, null, 'errors'); + $action = 'create'; + } + } + + if (!$error) { + $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', ''); + if (!($result > 0)) { + $error++; + setEventMessages($paiement->error, null, 'errors'); + } + } + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); } } - - if (!$error) { - $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', ''); - if (!($result > 0)) { - $error++; - setEventMessages($paiement->error, null, 'errors'); - } - } - - if (!$error) { - $db->commit(); - } else { - $db->rollback(); + if (empty($error)) { + header("Location: card.php?id=" . $object->id); + exit; } } - if (empty($error)) { - header("Location: card.php?id=" . $object->id); - exit; - } + + $action = 'create'; } - $action = 'create'; -} + if ($action == 'confirm_delete' && $confirm == 'yes') { + $result = $object->fetch($id); + $totalpaid = $object->getSommePaiement(); -if ($action == 'confirm_delete' && $confirm == 'yes') { - $result = $object->fetch($id); - $totalpaid = $object->getSommePaiement(); + if (empty($totalpaid)) { + $db->begin(); - if (empty($totalpaid)) { - $db->begin(); - - $ret = $object->delete($user); - if ($ret > 0) { - if ($object->fk_bank) { - $accountline = new AccountLine($db); - $result = $accountline->fetch($object->fk_bank); - if ($result > 0) { - $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing) + $ret = $object->delete($user); + if ($ret > 0) { + if ($object->fk_bank) { + $accountline = new AccountLine($db); + $result = $accountline->fetch($object->fk_bank); + if ($result > 0) { + $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing) + } } - } - if ($result >= 0) { - $db->commit(); - header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php'); - exit; + if ($result >= 0) { + $db->commit(); + header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php'); + exit; + } else { + $object->error = $accountline->error; + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } } else { - $object->error = $accountline->error; $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } } else { - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors'); - } -} - -if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) { - $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); - - if (empty($amount)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); - $action = 'edit'; - } elseif (!is_numeric($amount)) { - setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); - $action = 'create'; - } else { - $result = $object->fetch($id); - - $object->amount = $amount; - - $result = $object->update($user); - if ($result <= 0) { - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors'); } } -} -// Action clone object -if ($action == 'confirm_clone' && $confirm != 'yes') { - $action = ''; -} + if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) { + $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); -if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { - $db->begin(); - - $originalId = $id; - - $object->fetch($id); - - if ($object->id > 0) { - $object->id = $object->ref = null; - $object->paye = 0; - - if (GETPOST('amount', 'alphanohtml')) { - $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2); - } - - if (GETPOST('clone_label', 'alphanohtml')) { - $object->label = GETPOST('clone_label', 'alphanohtml'); + if (empty($amount)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'edit'; + } elseif (!is_numeric($amount)) { + setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'create'; } else { - $object->label = $langs->trans("CopyOf").' '.$object->label; + $result = $object->fetch($id); + + $object->amount = $amount; + + $result = $object->update($user); + if ($result <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } - - $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int')); - if ($newdateperiod) { - $object->datev = $newdateperiod; - } - - //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); } + + // Action clone object + if ($action == 'confirm_clone' && $confirm != 'yes') { + $action = ''; + } + + if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { + $db->begin(); + + $originalId = $id; + + $object->fetch($id); + + if ($object->id > 0) { + $object->id = $object->ref = null; + $object->paye = 0; + + if (GETPOST('amount', 'alphanohtml')) { + $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2); + } + + if (GETPOST('clone_label', 'alphanohtml')) { + $object->label = GETPOST('clone_label', 'alphanohtml'); + } else { + $object->label = $langs->trans("CopyOf").' '.$object->label; + } + + $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int')); + if ($newdateperiod) { + $object->datev = $newdateperiod; + } + + //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); + } + } + + // Actions to build doc + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } @@ -382,16 +387,7 @@ $title = $langs->trans("VAT")." - ".$langs->trans("Card"); $help_url = ''; llxHeader('', $title, $help_url); - -if ($id) { - $result = $object->fetch($id); - if ($result <= 0) { - dol_print_error($db); - exit; - } -} - -// Form to enter VAT +// Form to create a VAT if ($action == 'create') { print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New")); @@ -532,6 +528,8 @@ if ($action == 'create') { // View mode if ($id > 0) { + $formconfirm = ''; + $head = vat_prepare_head($object); $totalpaid = $object->getSommePaiement(); @@ -546,25 +544,37 @@ if ($id > 0) { $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1); $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100'); - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240); } if ($action == 'paid') { $text = $langs->trans('ConfirmPayVAT'); - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2); } if ($action == 'delete') { $text = $langs->trans('ConfirmDeleteVAT'); - print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2); + $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2); } if ($action == 'edit') { - print "