diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 27ba03499c8..385dc6dcd4c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -312,6 +312,15 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } + else if ($action == 'setdate_pointoftax' && $user->rights->facture->creer) + { + $object->fetch($id); + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + $object->date_pointoftax=$date_pointoftax; + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); + } + else if ($action == 'setconditions' && $user->rights->facture->creer) { $object->fetch($id); @@ -702,12 +711,15 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReplaceInvoice")), null, 'errors'); } + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + if (! $error) { // This is a replacement invoice $result = $object->fetch($_POST['fac_replacement']); $object->fetch_thirdparty(); $object->date = $dateinvoice; + $object->date_pointoftax = $date_pointoftax; $object->note_public = trim($_POST['note_public']); $object->note = trim($_POST['note']); $object->ref_client = $_POST['ref_client']; @@ -752,11 +764,14 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Date")), null, 'errors'); } + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + if (! $error) { $object->socid = GETPOST('socid','int'); $object->number = $_POST['facnumber']; $object->date = $dateinvoice; + $object->date_pointoftax = $date_pointoftax; $object->note_public = trim($_POST['note_public']); $object->note = trim($_POST['note']); $object->ref_client = $_POST['ref_client']; @@ -858,12 +873,15 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); } + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + if (! $error) { $object->socid = GETPOST('socid','int'); $object->type = $_POST['type']; $object->number = $_POST['facnumber']; - $object->date = $dateinvoice; + $object->date = $dateinvoice; + $object->date_pointoftax = $date_pointoftax; $object->note_public = trim($_POST['note_public']); $object->note_private = trim($_POST['note_private']); $object->ref_client = $_POST['ref_client']; @@ -904,6 +922,8 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); } + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + if (! $error) { // Si facture standard @@ -911,6 +931,7 @@ if (empty($reshook)) $object->type = GETPOST('type'); $object->number = $_POST['facnumber']; $object->date = $dateinvoice; + $object->date_pointoftax = $date_pointoftax; $object->note_public = trim($_POST['note_public']); $object->note_private = trim($_POST['note_private']); $object->ref_client = $_POST['ref_client']; @@ -1203,7 +1224,7 @@ if (empty($reshook)) { // If some invoice's lines coming from page $id = $object->create($user); - for($i = 1; $i <= $NBLINES; $i ++) { + for ($i = 1; $i <= $NBLINES; $i ++) { if ($_POST['idprod' . $i]) { $product = new Product($db); $product->fetch($_POST['idprod' . $i]); @@ -1224,6 +1245,8 @@ if (empty($reshook)) $mesg = '
' . $langs->trans("ErrorFieldRequired", $langs->trans("Date")) . '
'; } + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + if (!($_POST['situations'] > 0)) { $error++; $mesg = '
' . $langs->trans("ErrorFieldRequired", $langs->trans("InvoiceSituation")) . '
'; @@ -1248,6 +1271,7 @@ if (empty($reshook)) $object->fetch_thirdparty(); $object->date = $datefacture; + $object->date_pointoftax = $date_pointoftax; $object->note_public = trim($_POST['note_public']); $object->note = trim($_POST['note']); $object->ref_client = $_POST['ref_client']; @@ -2396,6 +2420,15 @@ if ($action == 'create') print $form->select_date($datefacture?$datefacture:$dateinvoice, '', '', '', '', "add", 1, 1, 1); print ''; + // Date point of tax + if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) + { + print '' . $langs->trans('DatePointOfTax') . ''; + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); + print $form->select_date($date_pointoftax?$date_pointoftax:-1, 'date_pointoftax', '', '', '', "add", 1, 1, 1); + print ''; + } + // Payment term print '' . $langs->trans('PaymentConditionsShort') . ''; $form->select_conditions_paiements(isset($_POST['cond_reglement_id']) ? $_POST['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id'); @@ -3460,6 +3493,24 @@ else if ($id > 0 || ! empty($ref)) print ''; + if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) + { + // Date invoice + print ''; + print ''; + print ''; + print '
'; + print $langs->trans('DatePointOfTax'); + print 'id . '">' . img_edit($langs->trans('SetDate'), 1) . '
'; + print ''; + if ($action == 'editdate_pointoftax') { + $form->form_date($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->date_pointoftax, 'date_pointoftax'); + } else { + print dol_print_date($object->date_pointoftax, 'daytext'); + } + print ''; + } + // Conditions de reglement print ''; print '
'; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index bea200f2656..6e46ead1da5 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -336,6 +336,7 @@ class Facture extends CommonInvoice $sql.= ", remise_absolue"; $sql.= ", remise_percent"; $sql.= ", datef"; + $sql.= ", date_pointoftax"; $sql.= ", note_private"; $sql.= ", note_public"; $sql.= ", ref_client, ref_int"; @@ -358,6 +359,7 @@ class Facture extends CommonInvoice $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); $sql.= ", ".($this->remise_percent>0?$this->remise_percent:'NULL'); $sql.= ", '".$this->db->idate($this->date)."'"; + $sql.= ", '".$this->db->idate($this->date_pointoftax)."'"; $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); $sql.= ", ".($this->ref_client?"'".$this->db->escape($this->ref_client)."'":"null"); @@ -665,6 +667,7 @@ class Facture extends CommonInvoice $facture->type = $this->type; $facture->socid = $this->socid; $facture->date = $this->date; + $facture->date_pointoftax = $this->date_pointoftax; $facture->note_public = $this->note_public; $facture->note_private = $this->note_private; $facture->ref_client = $this->ref_client; @@ -1014,7 +1017,7 @@ class Facture extends CommonInvoice $sql = 'SELECT f.rowid,f.facnumber,f.ref_client,f.ref_ext,f.ref_int,f.type,f.fk_soc,f.amount,f.tva, f.localtax1, f.localtax2, f.total, f.total_ttc, f.revenuestamp'; $sql.= ', f.remise_percent, f.remise_absolue, f.remise'; - $sql.= ', f.datef as df'; + $sql.= ', f.datef as df, f.date_pointoftax'; $sql.= ', f.date_lim_reglement as dlr'; $sql.= ', f.datec as datec'; $sql.= ', f.date_valid as datev'; @@ -1054,6 +1057,7 @@ class Facture extends CommonInvoice $this->ref_int = $obj->ref_int; $this->type = $obj->type; $this->date = $this->db->jdate($obj->df); + $this->date_pointoftax = $this->db->jdate($obj->date_pointoftax); $this->date_creation = $this->db->jdate($obj->datec); $this->date_validation = $this->db->jdate($obj->datev); $this->datem = $this->db->jdate($obj->datem); @@ -1328,6 +1332,7 @@ class Facture extends CommonInvoice $sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").","; $sql.= " datec=".(strval($this->date_creation)!='' ? "'".$this->db->idate($this->date_creation)."'" : 'null').","; $sql.= " datef=".(strval($this->date)!='' ? "'".$this->db->idate($this->date)."'" : 'null').","; + $sql.= " date_pointoftax=".(strval($this->date_pointoftax)!='' ? "'".$this->db->idate($this->date_pointoftax)."'" : 'null').","; $sql.= " date_valid=".(strval($this->date_validation)!='' ? "'".$this->db->idate($this->date_validation)."'" : 'null').","; $sql.= " paye=".(isset($this->paye)?$this->paye:"null").","; $sql.= " remise_percent=".(isset($this->remise_percent)?$this->remise_percent:"null").","; diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 046a47a699e..4615c783dfe 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1530,6 +1530,14 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetTextColor(0,0,60); $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R'); + if (! empty($conf->global->INVOICE_POINTOFTAX_DATE)) + { + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DatePointOfTax")." : " . dol_print_date($object->date_pointoftax,"day",false,$outputlangs), '', 'R'); + } + if ($object->type != 2) { $posy+=3; diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index f603846de50..140b0c15089 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -108,6 +108,8 @@ ALTER TABLE llx_cronjob ADD COLUMN test varchar(255) DEFAULT '1'; ALTER TABLE llx_facture ADD INDEX idx_facture_fk_statut (fk_statut); +ALTER TABLE llx_facture ADD COLUMN date_pointoftax date; + UPDATE llx_projet as p set p.opp_percent = (SELECT percent FROM llx_c_lead_status as cls WHERE cls.rowid = p.fk_opp_status) WHERE p.opp_percent IS NULL AND p.fk_opp_status IS NOT NULL; ALTER TABLE llx_facturedet ADD COLUMN fk_contract_line integer NULL AFTER rang; diff --git a/htdocs/install/mysql/tables/llx_facture.sql b/htdocs/install/mysql/tables/llx_facture.sql index b503401cd37..b8e97f4dc1e 100644 --- a/htdocs/install/mysql/tables/llx_facture.sql +++ b/htdocs/install/mysql/tables/llx_facture.sql @@ -37,8 +37,9 @@ create table llx_facture increment varchar(10), fk_soc integer NOT NULL, datec datetime, -- date de creation de la facture - datef date, -- date de la facture - date_valid date, -- date de validation + datef date, -- date invoice + date_pointoftax date, -- date point of tax (for GB) + date_valid date, -- date validation tms timestamp, -- date creation/modification paye smallint DEFAULT 0 NOT NULL, amount double(24,8) DEFAULT 0 NOT NULL, diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index a4e2ba643b3..a94c192ef4a 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -223,6 +223,7 @@ RelatedRecurringCustomerInvoices=Related recurring customer invoices MenuToValid=To valid DateMaxPayment=Payment due before DateInvoice=Invoice date +DatePointOfTax=Point of tax NoInvoice=No invoice ClassifyBill=Classify invoice SupplierBillsToPay=Unpaid supplier invoices