From 3599f2c840ce3af24f7ed7af0005d4c2383ebcf1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Tue, 4 Oct 2016 12:31:45 +0200 Subject: [PATCH] Uniformize code for recurring invoices --- htdocs/compta/facture.php | 100 +------------- .../facture/class/facture-rec.class.php | 3 +- htdocs/compta/facture/fiche-rec.php | 128 ++++++++++++++---- htdocs/core/class/html.form.class.php | 4 +- htdocs/core/lib/functions.lib.php | 4 + .../install/mysql/migration/4.0.0-5.0.0.sql | 2 + htdocs/install/mysql/tables/llx_facture.sql | 2 +- .../install/mysql/tables/llx_facture_rec.sql | 3 +- 8 files changed, 114 insertions(+), 132 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 6ced019c076..551dacfcafc 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2898,7 +2898,7 @@ else if ($id > 0 || ! empty($ref)) $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); + $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); // Project if (! empty($conf->projet->enabled)) { @@ -2943,73 +2943,6 @@ else if ($id > 0 || ! empty($ref)) print '<table class="border" width="100%">'; - // Ref - /* - print '<tr><td class="titlefield">' . $langs->trans('Ref') . '</td>'; - print '<td colspan="5">'; - $morehtmlright = ''; - $discount = new DiscountAbsolute($db); - $result = $discount->fetch(0, $object->id); - if ($result > 0) { - $morehtmlright = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", $discount->getNomUrl(1, 'discount')) . ')'; - } - if ($result < 0) { - dol_print_error('', $discount->error); - } - print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', '', '', 0, '', '', $morehtmlright); - print '</td></tr>'; - - // Ref customer - print '<tr><td>'; - print '<table class="nobordernopadding" width="100%"><tr><td>'; - print $langs->trans('RefCustomer'); - print '</td>'; - if ($action != 'refclient' && ! empty($object->brouillon)) - print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=refclient&id=' . $object->id . '">' . img_edit($langs->trans('Modify')) . '</a></td>'; - print '</tr></table>'; - print '</td>'; - print '<td colspan="5">'; - if ($user->rights->facture->creer && $action == 'refclient') { - print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">'; - print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">'; - print '<input type="hidden" name="action" value="set_ref_client">'; - print '<input type="text" class="flat" size="20" name="ref_client" value="' . $object->ref_client . '">'; - print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">'; - print '</form>'; - } else { - print $object->ref_client; - } - print '</td></tr>'; - - // Third party - print '<tr><td>'; - print '<table class="nobordernopadding" width="100%">'; - print '<tr><td>' . $langs->trans('Company') . '</td>'; - print '</td><td colspan="5">'; - if (! empty($conf->global->FACTURE_CHANGE_THIRDPARTY) && $action != 'editthirdparty' && $object->brouillon && $user->rights->facture->creer) - print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editthirdparty&facid=' . $object->id . '">' . img_edit($langs->trans('SetLinkToAnotherThirdParty'), 1) . '</a></td>'; - print '</tr></table>'; - print '</td><td colspan="5">'; - if ($action == 'editthirdparty') { - $form->form_thirdparty($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, 'socid','client>0'); - } else { - print ' ' . $soc->getNomUrl(1, 'compta'); - print ' '; - print '(<a href="' . DOL_URL_ROOT . '/compta/facture/list.php?socid=' . $object->socid . '">' . $langs->trans('OtherBills') . '</a>'; - // Outstanding Bill - $outstandingBills = $soc->get_OutstandingBill(); - print ' - ' . $langs->trans('CurrentOutstandingBill') . ': '; - print price($outstandingBills, '', $langs, 0, 0, - 1, $conf->currency); - if ($soc->outstanding_limit != '') - { - if ($outstandingBills > $soc->outstanding_limit) - print img_warning($langs->trans("OutstandingBillReached")); - print ' / ' . price($soc->outstanding_limit); - } - print ')'; - } - print '</tr>';*/ - // Type print '<tr><td class="titlefield">' . $langs->trans('Type') . '</td><td>'; print $object->getLibType(); @@ -3338,37 +3271,6 @@ else if ($id > 0 || ! empty($ref)) } } - // Statut - /* - print '<tr><td>' . $langs->trans('Status') . '</td>'; - print '<td colspan="3">' . ($object->getLibStatut(4, $totalpaye)) . '</td></tr>'; - - // Project - if (! empty($conf->projet->enabled)) { - $langs->load('projects'); - print '<tr>'; - print '<td>'; - - print '<table class="nobordernopadding" width="100%"><tr><td>'; - print $langs->trans('Project'); - print '</td>'; - if ($action != 'classify') { - print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=classify&facid=' . $object->id . '">'; - print img_edit($langs->trans('SetProject'), 1); - print '</a></td>'; - } - print '</tr></table>'; - - print '</td><td colspan="3">'; - if ($action == 'classify') { - $form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1); - } else { - $form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0); - } - print '</td>'; - print '</tr>'; - }*/ - // Incoterms if (!empty($conf->incoterm->enabled)) { diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 007c8040d0d..cd7c9dd7ae8 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -42,7 +42,8 @@ class FactureRec extends CommonInvoice public $table_element='facture_rec'; public $table_element_line='facturedet_rec'; public $fk_element='fk_facture'; - + public $picto='bill'; + var $entity; var $number; var $date; diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 2862b98ca4e..33da64e3221 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -31,10 +31,12 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; -require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +if (! empty($conf->projet->enabled)) { + require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; +} $langs->load('bills'); $langs->load('compta'); @@ -297,12 +299,14 @@ if (empty($reshook)) // Set bank account elseif ($action == 'setref' && $user->rights->facture->creer) { + //var_dump(GETPOST('ref', 'alpha'));exit; $result=$object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); if ($result > 0) { $object->titre = GETPOST('ref', 'alpha'); $object->ref = $object->titre; } + else dol_print_error($db, $object->error, $object->errors); } // Set bank account elseif ($action == 'setbankaccount' && $user->rights->facture->creer) @@ -863,6 +867,7 @@ llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture- $form = new Form($db); $formother = new FormOther($db); +if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } $companystatic = new Societe($db); $now = dol_now(); @@ -1069,11 +1074,64 @@ else dol_fiche_head($head, 'card', $langs->trans("RepeatableInvoice"),0,'bill'); // Add a div - print '<table class="border" width="100%">'; - + // Recurring invoice content + $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/fiche-rec.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; + + $morehtmlref=''; + if ($action != 'editref') $morehtmlref.=$form->editfieldkey($object->ref, 'ref', $object->ref, $object, $user->rights->facture->creer, '', '', 0, 2); + else $morehtmlref.= $form->editfieldval('', 'ref', $object->ref, $object, $user->rights->facture->creer, 'string'); + + $morehtmlref.='<div class="refidno">'; + // Ref customer + //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); + //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='<br>'.$langs->trans('Project') . ' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; + $morehtmlref.='<input type="hidden" name="action" value="classin">'; + $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; + $morehtmlref.='</form>'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">'; + $morehtmlref.=$proj->ref; + $morehtmlref.='</a>'; + } else { + $morehtmlref.=''; + } + } + } + $morehtmlref.='</div>'; + + dol_banner_tab($object, 'ref', $linkback, 1, 'titre', 'none', $morehtmlref, '', 0, '', $morehtmlright); + + print '<div class="fichecenter">'; + print '<div class="fichehalfleft">'; + print '<div class="underbanner clearboth"></div>'; + + print '<table class="border" width="100%">'; // Ref + /* print '<tr><td class="titlefield">'; //print $langs->trans('Ref'); print $form->editfieldkey($langs->trans("Ref"), 'ref', $object->ref, $object, $user->rights->facture->creer); @@ -1083,11 +1141,11 @@ else print $form->showrefnav($object, 'ref', $linkback, 1, 'titre', 'none', $morehtmlref); print '</td></tr>'; - print '<tr><td>'.$langs->trans("Customer").'</td>'; print '<td colspan="3">'.$object->thirdparty->getNomUrl(1,'customer').'</td></tr>'; - - print "<tr><td>".$langs->trans("Author").'</td><td colspan="3">'.$author->getFullName($langs)."</td></tr>"; + */ + + print '<tr><td class="titlefield">'.$langs->trans("Author").'</td><td colspan="3">'.$author->getFullName($langs)."</td></tr>"; print '<tr><td>'.$langs->trans("AmountHT").'</td>'; print '<td colspan="3">'.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).'</td>'; @@ -1158,6 +1216,7 @@ else print '</tr>'; // Project + /* if (! empty($conf->projet->enabled)) { $langs->load('projects'); @@ -1182,7 +1241,7 @@ else } print '</td>'; print '</tr>'; - } + }*/ // Bank Account print '<tr><td class="nowrap">'; @@ -1204,10 +1263,15 @@ else print "</td>"; print '</tr>'; - print "</table>"; - - print '<br>'; - + print '</table>'; + + print '</div>'; + print '<div class="fichehalfright">'; + print '<div class="ficheaddleft">'; + print '<div class="underbanner clearboth"></div>'; + + print '<table class="border centpercent">'; + /* * Recurrence */ @@ -1217,14 +1281,14 @@ else print '<table class="border" width="100%">'; // if "frequency" is empty or = 0, the reccurence is disabled - print '<tr><td class="titlefield">'; + print '<tr><td style="width: 50%">'; print '<table class="nobordernopadding" width="100%"><tr><td>'; print $langs->trans('Frequency'); print '</td>'; if ($action != 'editfrequency' && ! empty($object->brouillon) && $user->rights->facture->creer) print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editfrequency&facid=' . $object->id . '">' . img_edit($langs->trans('Edit'), 1) . '</a></td>'; print '</tr></table>'; - print '</td><td colspan="5">'; + print '</td><td>'; if ($action == 'editfrequency') { print '<form method="post" action="'.$_SERVER["PHP_SELF"] . '?facid=' . $object->id.'">'; @@ -1260,7 +1324,7 @@ else { print $langs->trans("NextDateToExecution"); } - print '</td><td colspan="5">'; + print '</td><td>'; if ($action == 'date_when' || $object->frequency > 0) { print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day'); @@ -1278,7 +1342,7 @@ else { print $langs->trans("MaxPeriodNumber"); } - print '</td><td colspan="5">'; + print '</td><td>'; if ($action == 'nb_gen_max' || $object->frequency > 0) { print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max?$object->nb_gen_max:'', $object, $user->rights->facture->creer); @@ -1296,7 +1360,7 @@ else print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer); else print $langs->trans("StatusOfGeneratedInvoices"); - print '</td><td colspan="5">'; + print '</td><td>'; $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated'); if ($action == 'auto_validate' || $object->frequency > 0) { @@ -1307,20 +1371,21 @@ else print '</table>'; - print '<br>'; - // Frequencry/Recurring section - if ($object->frequency > 0) - { - if (empty($conf->cron->enabled)) - { - print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"))); - } + if ($object->frequency > 0) + { + print '<br>'; + + if (empty($conf->cron->enabled)) + { + print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"))); + } - print '<table class="border" width="100%">'; + print '<div class="underbanner clearboth"></div>'; + print '<table class="border centpercent">'; // Nb of generation already done - print '<tr><td class="titlefield">'.$langs->trans("NbOfGenerationDone").'</td>'; + print '<tr><td style="width: 50%">'.$langs->trans("NbOfGenerationDone").'</td>'; print '<td>'; print $object->nb_gen_done?$object->nb_gen_done:'0'; print '</td>'; @@ -1329,7 +1394,7 @@ else // Date last print '<tr><td>'; print $langs->trans("DateLastGeneration"); - print '</td><td colspan="5">'; + print '</td><td>'; print dol_print_date($object->date_last_gen, 'dayhour'); print '</td>'; print '</tr>'; @@ -1339,6 +1404,13 @@ else print '<br>'; } + print '</div>'; + print '</div>'; + print '</div>'; + + print '<div class="clearboth"></div><br>'; + + // Lines print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST"> <input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '"> diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index eddff48b1fe..cc21279eacf 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -80,7 +80,7 @@ class Form * @param string $typeofdata Type of data ('string' by default, 'email', 'amount:99', 'numeric:99', 'text' or 'textarea:rows:cols', 'datepicker' ('day' do not work, don't know why), 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select;xxx[:class]'...) * @param string $moreparam More param to add on a href URL* * @param int $fieldrequired 1 if we want to show field as mandatory using the "fieldrequired" CSS. - * @param int $notabletag Do no output table tags + * @param int $notabletag 1=Do not output table tags but output a ':', 2=Do not output table tags and no ':' * @return string HTML edit field */ function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='', $fieldrequired=0, $notabletag=0) @@ -118,7 +118,7 @@ class Form if (empty($notabletag) && GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='</td>'; if (empty($notabletag) && GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right">'; if ($htmlname && GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&id='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>'; - if (! empty($notabletag)) $ret.=' : '; + if (! empty($notabletag) && $notabletag == 1) $ret.=' : '; if (empty($notabletag) && GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='</td>'; if (empty($notabletag) && GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='</tr></table>'; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 828c4c301ff..3c3cfc9267a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -992,6 +992,10 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt=$object->getLibStatut(5, $object->totalpaye); $morehtmlright.=$tmptxt; } + elseif ($object->element == 'facturerec') + { + $morehtmlright.='<!-- No status for recurring invoice -->'; + } else { $tmptxt=$object->getLibStatut(6); if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt=$object->getLibStatut(5); diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index aefe62a0189..3d2e2cbeedc 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -27,6 +27,8 @@ ALTER TABLE llx_product_lot MODIFY COLUMN entity integer DEFAULT 1; UPDATE llx_product_lot SET entity = 1 WHERE entity IS NULL; +ALTER TABLE llx_facture_rec ADD COLUMN fk_user_modif integer; + ALTER TABLE llx_adherent ADD COLUMN model_pdf varchar(255); ALTER TABLE llx_don ADD COLUMN date_valid datetime; diff --git a/htdocs/install/mysql/tables/llx_facture.sql b/htdocs/install/mysql/tables/llx_facture.sql index f62d8452953..aaf467a06b0 100644 --- a/htdocs/install/mysql/tables/llx_facture.sql +++ b/htdocs/install/mysql/tables/llx_facture.sql @@ -60,7 +60,7 @@ create table llx_facture fk_statut smallint DEFAULT 0 NOT NULL, fk_user_author integer, -- user making creation - fk_user_modif integer, -- user making last change + fk_user_modif integer, -- user making last change fk_user_valid integer, -- user validating fk_facture_source integer, -- facture origine si facture avoir diff --git a/htdocs/install/mysql/tables/llx_facture_rec.sql b/htdocs/install/mysql/tables/llx_facture_rec.sql index 4a65f4389b5..d0d79ef57dc 100644 --- a/htdocs/install/mysql/tables/llx_facture_rec.sql +++ b/htdocs/install/mysql/tables/llx_facture_rec.sql @@ -39,7 +39,8 @@ create table llx_facture_rec total double(24,8) DEFAULT 0, total_ttc double(24,8) DEFAULT 0, - fk_user_author integer, -- createur + fk_user_author integer, -- user creating + fk_user_modif integer, -- user making last change fk_projet integer, -- projet auquel est associe la facture -- GitLab