--- /tmp/dsg/dolibarr/htdocs/compta/facture/github_card-rec.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_card-rec.php @@ -117,8 +117,6 @@ $now = dol_now(); -$error = 0; - /* * Actions @@ -156,7 +154,7 @@ // Create predefined invoice if ($action == 'add') { - if (!GETPOST('title', 'alphanohtml')) + if (!GETPOST('titre', 'nohtml')) { setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors'); $action = "create"; @@ -190,18 +188,18 @@ if (!$error) { - $object->titre = GETPOST('title', 'nohtml'); // deprecated - $object->title = GETPOST('title', 'nohtml'); - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->model_pdf = GETPOST('modelpdf', 'alpha'); + $object->titre = GETPOST('titre', 'nohtml'); // deprecated + $object->title = GETPOST('titre', 'nohtml'); + $object->note_private = GETPOST('note_private', 'none'); + $object->note_public = GETPOST('note_public', 'none'); + $object->modelpdf = GETPOST('modelpdf', 'alpha'); $object->usenewprice = GETPOST('usenewprice', 'alpha'); $object->frequency = $frequency; $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); $object->nb_gen_max = $nb_gen_max; $object->auto_validate = GETPOST('auto_validate', 'int'); - $object->generate_pdf = GETPOST('generate_pdf', 'int'); + $object->generate_pdf = GETPOST('generate_pdf', 'int'); $object->fk_project = $projectid; $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); @@ -240,7 +238,9 @@ setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors'); $action = "create"; } - } else { + } + else + { $error++; setEventMessages($object->error, $object->errors, 'errors'); $action = "create"; @@ -252,7 +252,9 @@ header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$object->id); exit; - } else { + } + else + { $db->rollback(); $error++; @@ -277,63 +279,68 @@ if ($action == 'setconditions' && $user->rights->facture->creer) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - } // Set mode + } + // Set mode elseif ($action == 'setmode' && $user->rights->facture->creer) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - } // Set project + } + // Set project elseif ($action == 'classin' && $user->rights->facture->creer) { $object->setProject(GETPOST('projectid', 'int')); - } // Set bank account + } + // Set bank account elseif ($action == 'setref' && $user->rights->facture->creer) { //var_dump(GETPOST('ref', 'alpha'));exit; - $result = $object->setValueFrom('titre', $ref, '', null, 'text', '', $user, 'BILLREC_MODIFY'); + $result = $object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); if ($result > 0) { - $object->titre = $ref; // deprecated - $object->title = $ref; + $object->titre = GETPOST('ref', 'alpha'); // deprecated + $object->title = GETPOST('ref', 'alpha'); $object->ref = $object->title; - } else { - $error++; - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans('ErrorRefAlreadyExists', $ref), null, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } // Set bank account + } + else dol_print_error($db, $object->error, $object->errors); + } + // Set bank account elseif ($action == 'setbankaccount' && $user->rights->facture->creer) { $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - } // Set frequency and unit frequency + } + // Set frequency and unit frequency elseif ($action == 'setfrequency' && $user->rights->facture->creer) { $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha')); - } // Set next date of execution + } + // Set next date of execution elseif ($action == 'setdate_when' && $user->rights->facture->creer) { $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear')); if (!empty($date)) $object->setNextDate($date); - } // Set max period + } + // Set max period elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer) { $object->setMaxPeriod(GETPOST('nb_gen_max', 'int')); - } // Set auto validate + } + // Set auto validate elseif ($action == 'setauto_validate' && $user->rights->facture->creer) { $object->setAutoValidate(GETPOST('auto_validate', 'int')); - } // Set generate pdf + } + // Set generate pdf elseif ($action == 'setgenerate_pdf' && $user->rights->facture->creer) { $object->setGeneratepdf(GETPOST('generate_pdf', 'int')); - } // Set model pdf + } + // Set model pdf elseif ($action == 'setmodelpdf' && $user->rights->facture->creer) { $object->setModelpdf(GETPOST('modelpdf', 'alpha')); - } // Set status disabled + } + + // Set status disabled elseif ($action == 'disable' && $user->rights->facture->creer) { $db->begin(); @@ -349,11 +356,15 @@ if (!$error) { $db->commit(); - } else { + } + else + { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } - } // Set status enabled + } + + // Set status enabled elseif ($action == 'enable' && $user->rights->facture->creer) { $db->begin(); @@ -369,14 +380,19 @@ if (!$error) { $db->commit(); - } else { + } + else + { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } - } // Multicurrency Code + } + // Multicurrency Code elseif ($action == 'setmulticurrencycode' && $usercancreate) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } // Multicurrency rate + } + + // Multicurrency rate elseif ($action == 'setmulticurrencyrate' && $usercancreate) { $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); } @@ -402,20 +418,25 @@ { $db->commit(); $object->fetch($object->id); // Reload lines - } else { + } + else + { $db->rollback(); setEventMessages($db->lasterror(), null, 'errors'); } - } else { + } + else + { $db->rollback(); setEventMessages($line->error, $line->errors, 'errors'); } - } elseif ($action == 'update_extras') + } + elseif ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (!$error) @@ -437,20 +458,22 @@ // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); - $price_ht = price2num(GETPOST('price_ht'), 'MU', 2); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2); + $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $price_ht = GETPOST('price_ht'); + $price_ht_devise = GETPOST('multicurrency_price_ht'); $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha'); if ($prod_entry_mode == 'free') { $idprod = 0; $tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0); - } else { + } + else + { $idprod = GETPOST('idprod', 'int'); $tva_tx = ''; } - $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); + $qty = GETPOST('qty'.$predef); $remise_percent = GETPOST('remise_percent'.$predef); // Extrafields @@ -547,14 +570,17 @@ { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); - } // On reevalue prix selon taux tva car taux tva transaction peut etre different + } + // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). elseif ($tmpvat != $tmpprodvat) { if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); - } else { + } + else + { $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); } } @@ -577,7 +603,9 @@ } $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description; - } else { + } + else + { $desc = $prod->description; } @@ -612,7 +640,9 @@ $type = $prod->type; $fk_unit = $prod->fk_unit; - } else { + } + else + { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0); @@ -642,7 +672,9 @@ if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessages($mesg, null, 'errors'); - } else { + } + else + { // Insert line $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill, $fournprice, $buyingprice); @@ -660,7 +692,7 @@ $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - $model=$object->model_pdf; + $model=$object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -706,14 +738,18 @@ unset($_POST['situations']); unset($_POST['progress']); - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; } } - } elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) + } + + elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) { if (!$object->fetch($id) > 0) dol_print_error($db); $object->fetch_thirdparty(); @@ -723,11 +759,11 @@ $date_end = ''; //$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); //$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); - $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml')); - $pu_ht = price2num(GETPOST('price_ht'), '', 2); + $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'none') ? GETPOST('product_desc', 'none') : GETPOST('desc', 'none')); + $pu_ht = GETPOST('price_ht'); $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); $qty = GETPOST('qty'); - $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); + $pu_ht_devise = GETPOST('multicurrency_subprice'); // Define info_bits $info_bits = 0; @@ -871,7 +907,7 @@ } $ret = $object->fetch($id); // Reload to get new records - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); }*/ $object->fetch($object->id); // Reload lines @@ -911,7 +947,9 @@ unset($_POST['situations']); unset($_POST['progress']); - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -923,8 +961,7 @@ * View */ -$help_url = ''; -llxHeader('', $langs->trans("RepeatableInvoices"), $help_url); +llxHeader('', $langs->trans("RepeatableInvoices"), 'ch-facture.html#s-fac-facture-rec'); $form = new Form($db); $formother = new FormOther($db); @@ -956,7 +993,7 @@ print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="facid" value="'.$object->id.'">'; - print dol_get_fiche_head(null, '', '', 0); + dol_fiche_head(null, '', '', 0); $rowspan = 4; if (!empty($conf->projet->enabled)) $rowspan++; @@ -968,15 +1005,15 @@ // Title print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Title").'</td><td>'; - print '<input class="flat quatrevingtpercent" type="text" name="title" value="'.dol_escape_htmltag(GETPOST("titre", 'alphanohtml')).'">'; + print '<input class="flat quatrevingtpercent" type="text" name="titre" value="'.$_POST["titre"].'">'; print '</td></tr>'; // Third party print '<tr><td class="titlefieldcreate">'.$langs->trans("Customer").'</td><td>'.$object->thirdparty->getNomUrl(1, 'customer').'</td>'; print '</tr>'; - $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $object->note_public; - $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $object->note_private; + $note_public = GETPOST('note_public', 'none') ?GETPOST('note_public', 'none') : $object->note_public; + $note_private = GETPOST('note_private', 'none') ?GETPOST('note_private', 'none') : $object->note_private; // Help of substitution key $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object); @@ -1058,23 +1095,23 @@ print "</td></tr>"; } - // Model pdf - print "<tr><td>".$langs->trans('Model')."</td><td>"; - include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; - $list = ModelePDFFactures::liste_modeles($db); - print $form->selectarray('modelpdf', $list, $conf->global->FACTURE_ADDON_PDF); - print "</td></tr>"; + // Model pdf + print "<tr><td>".$langs->trans('Model')."</td><td>"; + include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; + $list = ModelePDFFactures::liste_modeles($db); + print $form->selectarray('modelpdf', $list, $conf->global->FACTURE_ADDON_PDF); + print "</td></tr>"; print "</table>"; - print dol_get_fiche_end(); + dol_fiche_end(); // Autogeneration $title = $langs->trans("Recurrence"); print load_fiche_titre('<span class="fa fa-calendar"></span> '.$title, '', ''); - print dol_get_fiche_head(null, '', '', 0); + dol_fiche_head(null, '', '', 0); print '<table class="border centpercent">'; @@ -1107,13 +1144,15 @@ $select = array('0'=>$langs->trans('DoNotGenerateDoc'), '1'=>$langs->trans('AutoGenerateDoc')); print $form->selectarray('generate_pdf', $select, GETPOST('generate_pdf')); print "</td></tr>"; - } else { + } + else + { print '<input type="hidden" name="generate_pdf" value="1">'; } print "</table>"; - print dol_get_fiche_end(); + dol_fiche_end(); $title = $langs->trans("ProductsAndServices"); @@ -1156,13 +1195,17 @@ print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'">'; print ' '; - print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">'; + print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">'; print '</div>'; print "</form>\n"; - } else { + } + else + { dol_print_error('', "Error, no invoice ".$object->id); } -} else { +} +else +{ /* * View mode */ @@ -1187,7 +1230,7 @@ $head = invoice_rec_prepare_head($object); - print dol_get_fiche_head($head, 'card', $langs->trans("RepeatableInvoice"), -1, 'bill'); // Add a div + dol_fiche_head($head, 'card', $langs->trans("RepeatableInvoice"), -1, 'bill'); // Add a div // Recurring invoice content @@ -1238,13 +1281,13 @@ } $morehtmlref .= '</div>'; - dol_banner_tab($object, 'ref', $linkback, 1, 'title', 'none', $morehtmlref, '', 0, '', $morehtmlright); + 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 centpercent tableforfield">'; + print '<table class="border centpercent">'; print '<tr><td class="titlefield">'.$langs->trans("Author").'</td><td>'.$author->getFullName($langs)."</td></tr>"; @@ -1273,7 +1316,7 @@ // Payment term print '<tr><td>'; - print '<table class="nobordernopadding centpercent"><tr><td>'; + print '<table class="nobordernopadding" width="100%"><tr><td>'; print $langs->trans('PaymentConditionsShort'); print '</td>'; if ($action != 'editconditions' && $user->rights->facture->creer) @@ -1285,7 +1328,9 @@ if ($action == 'editconditions') { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id'); - } else { + } + else + { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->cond_reglement_id, 'none'); } } else { @@ -1305,7 +1350,9 @@ if ($action == 'editmode') { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); - } else { + } + else + { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none'); } print '</td></tr>'; @@ -1338,7 +1385,7 @@ print '</td>'; if ($usercancreate && $action != 'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>'; - } + } print '</tr></table>'; print '</td><td>'; if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { @@ -1376,8 +1423,6 @@ // Only on template invoices $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen").' ('.$langs->trans("Example").': '.dol_print_date(($object->date_when ? $object->date_when : dol_now()), 'dayhour').')'; $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans("DateNextInvoiceAfterGen").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree(($object->date_when ? $object->date_when : dol_now()), $object->frequency, $object->unit_frequency), 'dayhour').')'; - $substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $object->nb_gen_done; - $substitutionarray['__INVOICE_COUNTER_MAX__'] = $object->nb_gen_max; $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>'; foreach ($substitutionarray as $key => $val) @@ -1414,36 +1459,40 @@ if ($action == 'editbankaccount') { $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { + } + else + { $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); } print "</td>"; print '</tr>'; - // Model pdf - print '<tr><td class="nowrap">'; - print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; - print $langs->trans('Model'); - print '<td>'; - if (($action != 'editmodelpdf') && $user->rights->facture->creer && $object->statut == FactureRec::STATUS_DRAFT) - print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmodelpdf&id='.$object->id.'">'.img_edit($langs->trans('SetModel'), 1).'</a></td>'; - print '</tr></table>'; - print '</td><td>'; - if ($action == 'editmodelpdf') - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; - $list = array(); - $models = ModelePDFFactures::liste_modeles($db); - foreach ($models as $k => $model) { - $list[] = str_replace(':', '|', $k).':'.$model; - } - $select = 'select;'.implode(',', $list); - print $form->editfieldval($langs->trans("Model"), 'modelpdf', $object->model_pdf, $object, $user->rights->facture->creer, $select); - } else { - print $object->model_pdf; - } - print "</td>"; - print '</tr>'; + // Model pdf + print '<tr><td class="nowrap">'; + print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; + print $langs->trans('Model'); + print '<td>'; + if (($action != 'editmodelpdf') && $user->rights->facture->creer && $object->statut == FactureRec::STATUS_DRAFT) + print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmodelpdf&id='.$object->id.'">'.img_edit($langs->trans('SetModel'), 1).'</a></td>'; + print '</tr></table>'; + print '</td><td>'; + if ($action == 'editmodelpdf') + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; + $list = array(); + $models = ModelePDFFactures::liste_modeles($db); + foreach ($models as $k => $model) { + $list[] = str_replace(':', '|', $k).':'.$model; + } + $select = 'select;'.implode(',', $list); + print $form->editfieldval($langs->trans("Model"), 'modelpdf', $object->modelpdf, $object, $user->rights->facture->creer, $select); + } + else + { + print $object->modelpdf; + } + print "</td>"; + print '</tr>'; // Other attributes $cols = 2; @@ -1463,7 +1512,7 @@ $title = $langs->trans("Recurrence"); //print load_fiche_titre($title, '', 'calendar'); - print '<table class="border centpercent tableforfield">'; + print '<table class="border centpercent">'; print '<tr><td colspan="2"><span class="fa fa-calendar"></span> '.$title.'</td></tr>'; @@ -1487,11 +1536,15 @@ print '</td>'; print '<td class="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>'; print '</tr></table></form>'; - } else { + } + else + { if ($object->frequency > 0) { print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency); - } else { + } + else + { print $langs->trans("NotARecurringInvoiceTemplate"); } } @@ -1502,7 +1555,9 @@ if ($action == 'date_when' || $object->frequency > 0) { print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day'); - } else { + } + else + { print $langs->trans("NextDateToExecution"); } print '</td><td>'; @@ -1514,7 +1569,9 @@ if (!$object->isMaxNbGenReached()) { if (!$object->suspended && $action != 'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) print img_warning($langs->trans("Late")); - } else { + } + else + { print img_info($langs->trans("MaxNumberOfGenerationReached")); } print '</td>'; @@ -1525,14 +1582,18 @@ if ($action == 'nb_gen_max' || $object->frequency > 0) { print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer); - } else { + } + else + { print $langs->trans("MaxPeriodNumber"); } 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); - } else { + } + else + { print ''; } print '</td>'; @@ -1542,7 +1603,8 @@ print '<tr><td>'; if ($action == 'auto_validate' || $object->frequency > 0) print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer); - else print $langs->trans("StatusOfGeneratedInvoices"); + else + print $langs->trans("StatusOfGeneratedInvoices"); print '</td><td>'; $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated'); if ($action == 'auto_validate' || $object->frequency > 0) @@ -1557,7 +1619,8 @@ print '<td>'; if ($action == 'generate_pdf' || $object->frequency > 0) print $form->editfieldkey($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $user->rights->facture->creer); - else print $langs->trans("StatusOfGeneratedDocuments"); + else + print $langs->trans("StatusOfGeneratedDocuments"); print '</td>'; print '<td>'; $select = 'select;0:'.$langs->trans('DoNotGenerateDoc').',1:'.$langs->trans('AutogenerateDoc'); @@ -1567,7 +1630,9 @@ } print '</td>'; print '</tr>'; - } else { + } + else + { print '<input type="hidden" name="generate_pdf" value="1">'; } @@ -1584,7 +1649,7 @@ } print '<div class="underbanner clearboth"></div>'; - print '<table class="border centpercent tableforfield">'; + print '<table class="border centpercent">'; // Nb of generation already done print '<tr><td style="width: 50%">'.$langs->trans("NbOfGenerationDone").'</td>'; @@ -1630,12 +1695,13 @@ // Show object lines if (!empty($object->lines)) { - $canchangeproduct = 1; + //$disableedit=1; + //$disablemove=1; $ret = $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice } // Form to add new line - if ($object->statut == $object::STATUS_DRAFT && $user->rights->facture->creer && $action != 'valid' && $action != 'editline') + if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline') { if ($action != 'editline') { @@ -1652,7 +1718,7 @@ print "</form>\n"; - print dol_get_fiche_end(); + dol_fiche_end(); /** @@ -1667,15 +1733,21 @@ if (!empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) { print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("MaxGenerationReached")).'">'.$langs->trans("CreateBill").'</a></div>'; - } else { + } + else + { if (empty($object->frequency) || $object->date_when <= $today) { print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->thirdparty->id.'&fac_rec='.$object->id.'">'.$langs->trans("CreateBill").'</a></div>'; - } else { + } + else + { print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("DateIsNotEnough")).'">'.$langs->trans("CreateBill").'</a></div>'; } } - } else { + } + else + { print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans("CreateBill").'</a></div>'; } } @@ -1685,7 +1757,9 @@ if (empty($object->suspended)) { print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/facture/card-rec.php?action=disable&id='.$object->id.'">'.$langs->trans("Disable").'</a></div>'; - } else { + } + else + { print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card-rec.php?action=enable&id='.$object->id.'">'.$langs->trans("Enable").'</a></div>'; } } --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_card.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_card.php @@ -75,7 +75,7 @@ $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $lineid = GETPOST('lineid', 'int'); @@ -175,20 +175,22 @@ // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) { - $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); - if ($result > 0) { - header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result); - exit(); - } else { - $langs->load("errors"); - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } - } // Change status of invoice + $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); + if ($result > 0) { + header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result); + exit(); + } else { + $langs->load("errors"); + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } + } + + // Change status of invoice elseif ($action == 'reopen' && $usercancreate) { $result = $object->fetch($id); @@ -201,7 +203,9 @@ setEventMessages($object->error, $object->errors, 'errors'); } } - } // Delete invoice + } + + // Delete invoice elseif ($action == 'confirm_delete' && $confirm == 'yes') { $result = $object->fetch($id); $object->fetch_thirdparty(); @@ -229,7 +233,9 @@ $action = ''; } } - } // Delete line + } + + // Delete line elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); @@ -251,7 +257,7 @@ } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $ret = $object->fetch($id); // Reload to get new records - $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } if ($result >= 0) { header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); @@ -261,13 +267,17 @@ setEventMessages($object->error, $object->errors, 'errors'); $action = ''; } - } // Delete link of credit note to invoice + } + + // Delete link of credit note to invoice elseif ($action == 'unlinkdiscount' && $usercancreate) { $discount = new DiscountAbsolute($db); $result = $discount->fetch(GETPOST("discountid")); $discount->unlink_invoice(); - } // Validation + } + + // Validation elseif ($action == 'valid' && $usercancreate) { $object->fetch($id); @@ -335,49 +345,76 @@ } } + elseif ($action == 'set_thirdparty' && $usercancreate) + { + $object->fetch($id); + $object->setValueFrom('fk_soc', $socid, '', null, 'int', '', $user, 'BILL_MODIFY'); + + header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); + exit(); + } + elseif ($action == 'classin' && $usercancreate) { $object->fetch($id); $object->setProject($_POST['projectid']); - } elseif ($action == 'setmode' && $usercancreate) + } + + elseif ($action == 'setmode' && $usercancreate) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); if ($result < 0) dol_print_error($db, $object->error); - } elseif ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) - { - $object->fetch($id); - $object->retained_warranty_fk_cond_reglement = 0; // To clean property - $result = $object->setRetainedWarrantyPaymentTerms(GETPOST('retained_warranty_fk_cond_reglement', 'int')); - if ($result < 0) dol_print_error($db, $object->error); - - $old_rw_date_lim_reglement = $object->retained_warranty_date_limit; - $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); - if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) $object->retained_warranty_date_limit = $new_rw_date_lim_reglement; - if ($object->retained_warranty_date_limit < $object->date) $object->retained_warranty_date_limit = $object->date; - $result = $object->update($user); - if ($result < 0) dol_print_error($db, $object->error); - } elseif ($action == 'setretainedwarranty' && $user->rights->facture->creer) { - $object->fetch($id); - $result = $object->setRetainedWarranty(GETPOST('retained_warranty', 'float')); - if ($result < 0) - dol_print_error($db, $object->error); - } elseif ($action == 'setretainedwarrantydatelimit' && $user->rights->facture->creer) { - $object->fetch($id); - $result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float')); - if ($result < 0) - dol_print_error($db, $object->error); - } // Multicurrency Code + } + + elseif ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) + { + $object->fetch($id); + $object->retained_warranty_fk_cond_reglement = 0; // To clean property + $result = $object->setRetainedWarrantyPaymentTerms(GETPOST('retained_warranty_fk_cond_reglement', 'int')); + if ($result < 0) dol_print_error($db, $object->error); + + $old_rw_date_lim_reglement = $object->retained_warranty_date_limit; + $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); + if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) $object->retained_warranty_date_limit = $new_rw_date_lim_reglement; + if ($object->retained_warranty_date_limit < $object->date) $object->retained_warranty_date_limit = $object->date; + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); + } + + elseif ($action == 'setretainedwarranty' && $user->rights->facture->creer) + { + $object->fetch($id); + $result = $object->setRetainedWarranty(GETPOST('retained_warranty', 'float')); + if ($result < 0) + dol_print_error($db, $object->error); + } + + elseif ($action == 'setretainedwarrantydatelimit' && $user->rights->facture->creer) + { + $object->fetch($id); + $result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float')); + if ($result < 0) + dol_print_error($db, $object->error); + } + + + // Multicurrency Code elseif ($action == 'setmulticurrencycode' && $usercancreate) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } // Multicurrency rate + } + + // Multicurrency rate elseif ($action == 'setmulticurrencyrate' && $usercancreate) { $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); - } elseif ($action == 'setinvoicedate' && $usercancreate) { + } + + elseif ($action == 'setinvoicedate' && $usercancreate) + { $object->fetch($id); $old_date_lim_reglement = $object->date_lim_reglement; - $date = dol_mktime(12, 0, 0, GETPOST('invoicedatemonth', 'int'), GETPOST('invoicedateday', 'int'), GETPOST('invoicedateyear', 'int')); + $date = dol_mktime(12, 0, 0, $_POST['invoicedatemonth'], $_POST['invoicedateday'], $_POST['invoicedateyear']); if (empty($date)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); @@ -392,7 +429,10 @@ if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setdate_pointoftax' && $usercancreate) { + } + + elseif ($action == 'setdate_pointoftax' && $usercancreate) + { $object->fetch($id); $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); $object->date_pointoftax = $date_pointoftax; @@ -400,42 +440,27 @@ if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setconditions' && $usercancreate) + } + + elseif ($action == 'setconditions' && $usercancreate) { $object->fetch($id); $object->cond_reglement_code = 0; // To clean property $object->cond_reglement_id = 0; // To clean property - - $error = 0; - - $db->begin(); - - if (!$error) { - $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if (!$error) { - $old_date_lim_reglement = $object->date_lim_reglement; - $new_date_lim_reglement = $object->calculate_date_lim_reglement(); - if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement; - if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date; - $result = $object->update($user); - if ($result < 0) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if ($error) { - $db->rollback(); - } else { - $db->commit(); - } - } elseif ($action == 'setpaymentterm' && $usercancreate) + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); + if ($result < 0) dol_print_error($db, $object->error); + + $old_date_lim_reglement = $object->date_lim_reglement; + $new_date_lim_reglement = $object->calculate_date_lim_reglement(); + if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement; + if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date; + $result = $object->update($user); + if ($result < 0) { + dol_print_error($db, $object->error); + } + } + + elseif ($action == 'setpaymentterm' && $usercancreate) { $object->fetch($id); $object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST['paymenttermmonth'], $_POST['paymenttermday'], $_POST['paymenttermyear']); @@ -447,7 +472,9 @@ if ($result < 0) { dol_print_error($db, $object->error); } - } elseif ($action == 'setrevenuestamp' && $usercancreate) + } + + elseif ($action == 'setrevenuestamp' && $usercancreate) { $object->fetch($id); $object->revenuestamp = GETPOST('revenuestamp'); @@ -468,26 +495,34 @@ $outputlangs->setDefaultLang($newlang); $outputlangs->load('products'); } - $model = $object->model_pdf; + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } } - } // Set incoterm + } + + // Set incoterm elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - } // bank account + } + + // bank account elseif ($action == 'setbankaccount' && $usercancreate) { $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - } elseif ($action == 'setremisepercent' && $usercancreate) + } + + elseif ($action == 'setremisepercent' && $usercancreate) { $object->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']); - } elseif ($action == "setabsolutediscount" && $usercancreate) + } + + elseif ($action == "setabsolutediscount" && $usercancreate) { // POST[remise_id] or POST[remise_id_for_payment] @@ -540,18 +575,24 @@ } $ret = $object->fetch($id); // Reload to get new records - $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'setref' && $usercancreate) + } + + elseif ($action == 'setref' && $usercancreate) { $object->fetch($id); $object->setValueFrom('ref', GETPOST('ref'), '', null, '', '', $user, 'BILL_MODIFY'); - } elseif ($action == 'setref_client' && $usercancreate) + } + + elseif ($action == 'setref_client' && $usercancreate) { $object->fetch($id); $object->set_ref_client(GETPOST('ref_client')); - } // Classify to validated + } + + // Classify to validated elseif ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate) { $idwarehouse = GETPOST('idwarehouse', 'int'); @@ -585,7 +626,9 @@ } } } - } else { + } + else + { //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY); if ($key == 'EMAIL') { @@ -654,19 +697,22 @@ $outputlangs->setDefaultLang($newlang); $outputlangs->load('products'); } - $model = $object->model_pdf; - + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - } else { + } + else + { if (count($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, $object->errors, 'errors'); } } - } // Go back to draft status (unvalidate) + } + + // Go back to draft status (unvalidate) elseif ($action == 'confirm_modif' && $usercanunvalidate) { $idwarehouse = GETPOST('idwarehouse', 'int'); @@ -739,7 +785,7 @@ $outputlangs->setDefaultLang($newlang); $outputlangs->load('products'); } - $model = $object->model_pdf; + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -747,7 +793,9 @@ } } } - } // Classify "paid" + } + + // Classify "paid" elseif ($action == 'confirm_paid' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); @@ -757,8 +805,8 @@ elseif ($action == 'confirm_paid_partially' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); - $close_code = GETPOST("close_code", 'restricthtml'); - $close_note = GETPOST("close_note", 'restricthtml'); + $close_code = GETPOST("close_code", 'none'); + $close_note = GETPOST("close_note", 'none'); if ($close_code) { $result = $object->set_paid($user, $close_code, $close_note); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); @@ -768,15 +816,17 @@ } // Classify "abandoned" elseif ($action == 'confirm_canceled' && $confirm == 'yes') { $object->fetch($id); - $close_code = GETPOST("close_code", 'restricthtml'); - $close_note = GETPOST("close_note", 'restricthtml'); + $close_code = GETPOST("close_code", 'none'); + $close_note = GETPOST("close_note", 'none'); if ($close_code) { $result = $object->set_canceled($user, $close_code, $close_note); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors'); } - } // Convertir en reduc + } + + // Convertir en reduc elseif ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); @@ -867,16 +917,16 @@ // Total credit note and deposit $total_creditnote_and_deposit = 0; - $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; - $sql .= " re.description, re.fk_facture_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; - $sql .= " WHERE fk_facture = ".$object->id; - $resql = $db->query($sql); - if (!empty($resql)) { - while ($obj = $db->fetch_object($resql)) { - $total_creditnote_and_deposit += $obj->amount_ttc; - } - } else dol_print_error($db); + $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; + $sql .= " re.description, re.fk_facture_source"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; + $sql .= " WHERE fk_facture = ".$object->id; + $resql = $db->query($sql); + if (!empty($resql)) { + while ($obj = $db->fetch_object($resql)) { + $total_creditnote_and_deposit += $obj->amount_ttc; + } + } else dol_print_error($db); $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc; $discount->amount_tva = 0; @@ -929,19 +979,25 @@ if ($result >= 0) { $db->commit(); - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); } } else { $db->commit(); } - } else { + } + else + { setEventMessages($discount->error, $discount->errors, 'errors'); $db->rollback(); } } - } // Delete payment + } + + // Delete payment elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); @@ -957,13 +1013,14 @@ setEventMessages($paiement->error, $paiement->errors, 'errors'); } } - } /* + } + + /* * Insert new invoice in database */ elseif ($action == 'add' && $usercancreate) { if ($socid > 0) $object->socid = GETPOST('socid', 'int'); - $selectedLines = GETPOST('toselect', 'array'); $db->begin(); @@ -984,39 +1041,39 @@ $action = 'create'; } - if (!(GETPOST('fac_replacement', 'int') > 0)) { + if (!($_POST['fac_replacement'] > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReplaceInvoice")), null, 'errors'); $action = 'create'; } - $date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int')); + $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(GETPOST('fac_replacement', 'int')); + $result = $object->fetch($_POST['fac_replacement']); $object->fetch_thirdparty(); $object->date = $dateinvoice; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim(GETPOST('note_public', 'restricthtml')); + $object->note_public = trim(GETPOST('note_public', 'none')); // We do not copy the private note - $object->ref_client = GETPOST('ref_client'); - //$object->ref_int = $_POST['ref_int']; - $object->model_pdf = GETPOST('model'); - $object->fk_project = GETPOST('projectid', 'int'); - $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int'); - $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); + $object->ref_client = $_POST['ref_client']; + $object->ref_int = $_POST['ref_int']; + $object->modelpdf = $_POST['model']; + $object->fk_project = $_POST['projectid']; + $object->cond_reglement_id = $_POST['cond_reglement_id']; + $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->fk_account = GETPOST('fk_account', 'int'); - $object->remise_absolue = GETPOST('remise_absolue', 'alpha'); - $object->remise_percent = GETPOST('remise_percent', 'alpha'); + $object->remise_absolue = $_POST['remise_absolue']; + $object->remise_percent = $_POST['remise_percent']; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); // Proprietes particulieres a facture de remplacement - $object->fk_facture_source = GETPOST('fac_replacement', 'int'); + $object->fk_facture_source = $_POST['fac_replacement']; $object->type = Facture::TYPE_REPLACEMENT; $id = $object->createFromCurrent($user); @@ -1027,7 +1084,7 @@ } // Credit note invoice - if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) + if ($_POST['type'] == Facture::TYPE_CREDIT_NOTE) { $sourceinvoice = GETPOST('fac_avoir'); if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) @@ -1045,7 +1102,7 @@ $action = 'create'; } - $date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int')); + $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); if (!$error) { @@ -1053,19 +1110,20 @@ $object->entity = $originentity; } $object->socid = GETPOST('socid', 'int'); - $object->ref = GETPOST('ref'); + $object->ref = $_POST['ref']; $object->date = $dateinvoice; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim(GETPOST('note_public', 'restricthtml')); + $object->note_public = trim(GETPOST('note_public', 'none')); // We do not copy the private note - $object->ref_client = GETPOST('ref_client'); - $object->model_pdf = GETPOST('model'); - $object->fk_project = GETPOST('projectid', 'int'); + $object->ref_client = $_POST['ref_client']; + $object->ref_int = $_POST['ref_int']; + $object->modelpdf = $_POST['model']; + $object->fk_project = $_POST['projectid']; $object->cond_reglement_id = 0; - $object->mode_reglement_id = GETPOST('mode_reglement_id'); + $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->fk_account = GETPOST('fk_account', 'int'); - $object->remise_absolue = GETPOST('remise_absolue'); - $object->remise_percent = GETPOST('remise_percent'); + $object->remise_absolue = $_POST['remise_absolue']; + $object->remise_percent = $_POST['remise_percent']; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); @@ -1078,12 +1136,12 @@ $facture_source = new Facture($db); // fetch origin object if ($facture_source->fetch($object->fk_facture_source) > 0) { - if ($facture_source->type == Facture::TYPE_SITUATION) - { - $object->situation_counter = $facture_source->situation_counter; - $object->situation_cycle_ref = $facture_source->situation_cycle_ref; - $facture_source->fetchPreviousNextSituationInvoice(); - } + if ($facture_source->type == Facture::TYPE_SITUATION) + { + $object->situation_counter = $facture_source->situation_counter; + $object->situation_cycle_ref = $facture_source->situation_cycle_ref; + $facture_source->fetchPreviousNextSituationInvoice(); + } } $id = $object->create($user); @@ -1114,84 +1172,86 @@ if ($facture_source->type == Facture::TYPE_SITUATION) { - $source_fk_prev_id = $line->fk_prev_id; // temporary storing situation invoice fk_prev_id - $line->fk_prev_id = $line->id; // The new line of the new credit note we are creating must be linked to the situation invoice line it is created from - - if (!empty($facture_source->tab_previous_situation_invoice)) - { - // search the last standard invoice in cycle and the possible credit note between this last and facture_source - // TODO Move this out of loop of $facture_source->lines - $tab_jumped_credit_notes = array(); - $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1; - $searchPreviousInvoice = true; - while ($searchPreviousInvoice) - { - if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1) - { - $searchPreviousInvoice = false; // find, exit; - break; - } else { - if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_CREDIT_NOTE) { - $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id; - } - $lineIndex--; // go to previous invoice in cycle - } - } - - $maxPrevSituationPercent = 0; - foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) - { - if ($prevLine->id == $source_fk_prev_id) - { - $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent); - - //$line->subprice = $line->subprice - $prevLine->subprice; - $line->total_ht = $line->total_ht - $prevLine->total_ht; - $line->total_tva = $line->total_tva - $prevLine->total_tva; - $line->total_ttc = $line->total_ttc - $prevLine->total_ttc; - $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1; - $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2; - - $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice; - $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht; - $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva; - $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc; - } - } - - // prorata - $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent; - - //print 'New line based on invoice id '.$facture_source->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>'; - - // If there is some credit note between last situation invoice and invoice used for credit note generation (note: credit notes are stored as delta) - $maxPrevSituationPercent = 0; - foreach ($tab_jumped_credit_notes as $index => $creditnoteid) { - foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) - { - if ($prevLine->fk_prev_id == $source_fk_prev_id) - { - $maxPrevSituationPercent = $prevLine->situation_percent; - - $line->total_ht -= $prevLine->total_ht; - $line->total_tva -= $prevLine->total_tva; - $line->total_ttc -= $prevLine->total_ttc; - $line->total_localtax1 -= $prevLine->total_localtax1; - $line->total_localtax2 -= $prevLine->total_localtax2; - - $line->multicurrency_subprice -= $prevLine->multicurrency_subprice; - $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht; - $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva; - $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc; - } - } - } - - // prorata - $line->situation_percent += $maxPrevSituationPercent; - - //print 'New line based on invoice id '.$facture_source->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>'; - } + $source_fk_prev_id = $line->fk_prev_id; // temporary storing situation invoice fk_prev_id + $line->fk_prev_id = $line->id; // The new line of the new credit note we are creating must be linked to the situation invoice line it is created from + + if (!empty($facture_source->tab_previous_situation_invoice)) + { + // search the last standard invoice in cycle and the possible credit note between this last and facture_source + // TODO Move this out of loop of $facture_source->lines + $tab_jumped_credit_notes = array(); + $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1; + $searchPreviousInvoice = true; + while ($searchPreviousInvoice) + { + if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1) + { + $searchPreviousInvoice = false; // find, exit; + break; + } + else + { + if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_CREDIT_NOTE) { + $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id; + } + $lineIndex--; // go to previous invoice in cycle + } + } + + $maxPrevSituationPercent = 0; + foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) + { + if ($prevLine->id == $source_fk_prev_id) + { + $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent); + + //$line->subprice = $line->subprice - $prevLine->subprice; + $line->total_ht = $line->total_ht - $prevLine->total_ht; + $line->total_tva = $line->total_tva - $prevLine->total_tva; + $line->total_ttc = $line->total_ttc - $prevLine->total_ttc; + $line->total_localtax1 = $line->total_localtax1 - $prevLine->total_localtax1; + $line->total_localtax2 = $line->total_localtax2 - $prevLine->total_localtax2; + + $line->multicurrency_subprice = $line->multicurrency_subprice - $prevLine->multicurrency_subprice; + $line->multicurrency_total_ht = $line->multicurrency_total_ht - $prevLine->multicurrency_total_ht; + $line->multicurrency_total_tva = $line->multicurrency_total_tva - $prevLine->multicurrency_total_tva; + $line->multicurrency_total_ttc = $line->multicurrency_total_ttc - $prevLine->multicurrency_total_ttc; + } + } + + // prorata + $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent; + + //print 'New line based on invoice id '.$facture_source->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>'; + + // If there is some credit note between last situation invoice and invoice used for credit note generation (note: credit notes are stored as delta) + $maxPrevSituationPercent = 0; + foreach ($tab_jumped_credit_notes as $index => $creditnoteid) { + foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) + { + if ($prevLine->fk_prev_id == $source_fk_prev_id) + { + $maxPrevSituationPercent = $prevLine->situation_percent; + + $line->total_ht -= $prevLine->total_ht; + $line->total_tva -= $prevLine->total_tva; + $line->total_ttc -= $prevLine->total_ttc; + $line->total_localtax1 -= $prevLine->total_localtax1; + $line->total_localtax2 -= $prevLine->total_localtax2; + + $line->multicurrency_subprice -= $prevLine->multicurrency_subprice; + $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht; + $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva; + $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc; + } + } + } + + // prorata + $line->situation_percent += $maxPrevSituationPercent; + + //print 'New line based on invoice id '.$facture_source->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>'; + } } $line->fk_facture = $object->id; @@ -1267,21 +1327,22 @@ if (!$error) { $object->socid = GETPOST('socid', 'int'); - $object->type = GETPOST('type'); - $object->ref = GETPOST('ref'); + $object->type = $_POST['type']; + $object->ref = $_POST['ref']; $object->date = $dateinvoice; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim(GETPOST('note_public', 'restricthtml')); - $object->note_private = trim(GETPOST('note_private', 'restricthtml')); - $object->ref_client = GETPOST('ref_client'); - $object->model_pdf = GETPOST('model'); - $object->fk_project = GETPOST('projectid', 'int'); - $object->cond_reglement_id = (GETPOST('type') == 3 ? 1 : GETPOST('cond_reglement_id')); - $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); + $object->note_public = trim(GETPOST('note_public', 'none')); + $object->note_private = trim(GETPOST('note_private', 'none')); + $object->ref_client = $_POST['ref_client']; + $object->ref_int = $_POST['ref_int']; + $object->modelpdf = $_POST['model']; + $object->fk_project = $_POST['projectid']; + $object->cond_reglement_id = ($_POST['type'] == 3 ? 1 : $_POST['cond_reglement_id']); + $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->fk_account = GETPOST('fk_account', 'int'); - $object->amount = price2num(GETPOST('amount')); - $object->remise_absolue = GETPOST('remise_absolue'); - $object->remise_percent = GETPOST('remise_percent'); + $object->amount = $_POST['amount']; + $object->remise_absolue = $_POST['remise_absolue']; + $object->remise_percent = $_POST['remise_percent']; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); @@ -1319,20 +1380,21 @@ // Si facture standard $object->socid = GETPOST('socid', 'int'); $object->type = GETPOST('type'); - $object->ref = GETPOST('ref'); + $object->ref = $_POST['ref']; $object->date = $dateinvoice; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim(GETPOST('note_public', 'restricthtml')); - $object->note_private = trim(GETPOST('note_private', 'restricthtml')); - $object->ref_client = GETPOST('ref_client'); - $object->model_pdf = GETPOST('model'); - $object->fk_project = GETPOST('projectid'); - $object->cond_reglement_id = (GETPOST('type') == 3 ? 1 : GETPOST('cond_reglement_id')); - $object->mode_reglement_id = GETPOST('mode_reglement_id'); + $object->note_public = trim(GETPOST('note_public', 'none')); + $object->note_private = trim(GETPOST('note_private', 'none')); + $object->ref_client = $_POST['ref_client']; + $object->ref_int = $_POST['ref_int']; + $object->modelpdf = $_POST['model']; + $object->fk_project = $_POST['projectid']; + $object->cond_reglement_id = ($_POST['type'] == 3 ? 1 : $_POST['cond_reglement_id']); + $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->fk_account = GETPOST('fk_account', 'int'); - $object->amount = price2num(GETPOST('amount')); - $object->remise_absolue = GETPOST('remise_absolue'); - $object->remise_percent = GETPOST('remise_percent'); + $object->amount = $_POST['amount']; + $object->remise_absolue = $_POST['remise_absolue']; + $object->remise_percent = $_POST['remise_percent']; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); @@ -1348,16 +1410,17 @@ if (in_array($object->type, $retainedWarrantyInvoiceAvailableType)) { $object->retained_warranty = GETPOST('retained_warranty', 'int'); $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); - } else { + } + else { $object->retained_warranty = 0; $object->retained_warranty_fk_cond_reglement = 0; } - $retained_warranty_date_limit = GETPOST('retained_warranty_date_limit'); - if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) { - $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit); - } - $object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); + $retained_warranty_date_limit = GETPOST('retained_warranty_date_limit'); + if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) { + $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit); + } + $object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); $object->fetch_thirdparty(); @@ -1451,11 +1514,14 @@ $amount_ttc_diff += $am; $amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline } - } else { + } + else + { if ($typeamount == 'amount') { $amountdeposit[0] = $valuedeposit; - } elseif ($typeamount == 'variable') + } + elseif ($typeamount == 'variable') { if ($result > 0) { @@ -1564,11 +1630,8 @@ $fk_parent_line = 0; $num = count($lines); - for ($i = 0; $i < $num; $i++) { - if (!in_array($lines[$i]->id, $selectedLines)) continue; // Skip unselected lines - // Don't add lines with qty 0 when coming from a shipment including all order lines if ($srcobject->element == 'shipping' && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS && $lines[$i]->qty == 0) continue; // Don't add closed lines when coming from a contract (Set constant to '0,5' to exclude also inactive lines) @@ -1639,7 +1702,7 @@ $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty); $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty); - $result = $object->addline( + $result = $object->addline( $desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid, @@ -1679,7 +1742,7 @@ $originidforcontact=$srcobject->origin_id; } $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$db->escape($originforcontact)."'"; + $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; $resqlcontact = $db->query($sqlcontact); if ($resqlcontact) @@ -1706,7 +1769,9 @@ setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } else { // If some invoice's lines coming from page + } + else + { // If some invoice's lines coming from page $id = $object->create($user); for ($i = 1; $i <= $NBLINES; $i++) { @@ -1729,21 +1794,21 @@ if (empty($datefacture)) { $error++; $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")); - setEventMessages($mesg, null, 'errors'); - } - - $date_pointoftax = dol_mktime(12, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int')); - - if (!(GETPOST('situations', 'int') > 0)) { + setEventMessages($mesg, null, 'errors'); + } + + $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->transnoentitiesnoconv("InvoiceSituation")); - setEventMessages($mesg, null, 'errors'); - $action = 'create'; + setEventMessages($mesg, null, 'errors'); + $action = 'create'; } if (!$error) { - $result = $object->fetch(GETPOST('situations', 'int')); - $object->fk_facture_source = GETPOST('situations', 'int'); + $result = $object->fetch($_POST['situations']); + $object->fk_facture_source = $_POST['situations']; $object->type = Facture::TYPE_SITUATION; if (!empty($origin) && !empty($originid)) @@ -1756,23 +1821,23 @@ // retained warranty if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) { - $retained_warranty = GETPOST('retained_warranty', 'int'); - if (price2num($retained_warranty) > 0) - { - $object->retained_warranty = price2num($retained_warranty); - } - - if (GETPOST('retained_warranty_fk_cond_reglement', 'int') > 0) - { - $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); - } - - $retained_warranty_date_limit = GETPOST('retained_warranty_date_limit'); - if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) { - $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit); - } - $object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); - } + $retained_warranty = GETPOST('retained_warranty', 'int'); + if (price2num($retained_warranty) > 0) + { + $object->retained_warranty = price2num($retained_warranty); + } + + if (GETPOST('retained_warranty_fk_cond_reglement', 'int') > 0) + { + $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); + } + + $retained_warranty_date_limit = GETPOST('retained_warranty_date_limit'); + if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) { + $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit); + } + $object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); + } foreach ($object->lines as $i => &$line) { @@ -1796,16 +1861,16 @@ // Si fk_remise_except defini on vérifie si la réduction à déjà été appliquée if ($line->fk_remise_except) { - $discount = new DiscountAbsolute($line->db); - $result = $discount->fetch($line->fk_remise_except); - if ($result > 0) - { - // Check if discount not already affected to another invoice - if ($discount->fk_facture_line > 0) - { - $line->fk_remise_except = 0; - } - } + $discount = new DiscountAbsolute($line->db); + $result = $discount->fetch($line->fk_remise_except); + if ($result > 0) + { + // Check if discount not already affected to another invoice + if ($discount->fk_facture_line > 0) + { + $line->fk_remise_except = 0; + } + } } } } @@ -1813,11 +1878,12 @@ $object->fetch_thirdparty(); $object->date = $datefacture; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim(GETPOST('note_public', 'restricthtml')); - $object->note = trim(GETPOST('note', 'restricthtml')); - $object->note_private = trim(GETPOST('note', 'restricthtml')); + $object->note_public = trim(GETPOST('note_public', 'none')); + $object->note = trim(GETPOST('note', 'none')); + $object->note_private = trim(GETPOST('note', 'none')); $object->ref_client = GETPOST('ref_client', 'alpha'); - $object->model_pdf = GETPOST('model', 'alpha'); + $object->ref_int = GETPOST('ref_int', 'alpha'); + $object->modelpdf = GETPOST('model', 'alpha'); $object->fk_project = GETPOST('projectid', 'int'); $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int'); $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); @@ -1831,7 +1897,9 @@ if ($id <= 0) { $mesg = $object->error; - } else { + } + else + { $nextSituationInvoice = new Facture($db); $nextSituationInvoice->fetch($id); @@ -1862,7 +1930,7 @@ $outputlangs->setDefaultLang($newlang); $outputlangs->load('products'); } - $model = $object->model_pdf; + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -1871,38 +1939,36 @@ header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); exit(); - } else { + } + else + { $db->rollback(); $action = 'create'; $_GET["origin"] = $_POST["origin"]; $_GET["originid"] = $_POST["originid"]; setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha') !== '') { - // Define vat_rate - $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0); - $vat_rate = str_replace('*', '', $vat_rate); - $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); - $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); - foreach ($object->lines as $line) { - $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice); - } - } elseif ($action == 'addline' && $usercancreate) // Add a new line + } + + // Add a new line + elseif ($action == 'addline' && $usercancreate) { $langs->load('errors'); $error = 0; // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc', 'none') ?GETPOST('dp_desc', 'restricthtml') : ''); - $price_ht = price2num(GETPOST('price_ht'), 'MU', 2); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2); + $product_desc = (GETPOST('dp_desc', 'none') ?GETPOST('dp_desc', 'none') : ''); + $price_ht = GETPOST('price_ht'); + $price_ht_devise = GETPOST('multicurrency_price_ht'); $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha'); if ($prod_entry_mode == 'free') { $idprod = 0; $tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0); - } else { + } + else + { $idprod = GETPOST('idprod', 'int'); $tva_tx = ''; } @@ -1949,7 +2015,9 @@ setEventMessages($langs->trans("ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv("UnitPriceHT"), $langs->transnoentitiesnoconv("CustomerAbsoluteDiscountShort")), null, 'errors'); } $error++; - } else { + } + else + { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); $error++; } @@ -1975,7 +2043,9 @@ if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) { $idprod = $res->fk_product_child; - } else { + } + else + { setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors'); $error++; } @@ -2027,18 +2097,21 @@ $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ? - if (!empty($price_ht) || $price_ht === '0') + if (!empty($price_ht)) { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); - } // On reevalue prix selon taux tva car taux tva transaction peut etre different + } + // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). elseif ($tmpvat != $tmpprodvat) { if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); - } else { + } + else + { $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); } } @@ -2156,7 +2229,7 @@ $outputlangs->setDefaultLang($newlang); $outputlangs->load('products'); } - $model = $object->model_pdf; + $model = $object->modelpdf; $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -2205,7 +2278,9 @@ $action = ''; } } - } elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) + } + + elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) { if (!$object->fetch($id) > 0) dol_print_error($db); $object->fetch_thirdparty(); @@ -2215,11 +2290,11 @@ $date_end = ''; $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); - $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml')); - $pu_ht = price2num(GETPOST('price_ht'), '', 2); + $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'none') ? GETPOST('product_desc', 'none') : GETPOST('desc', 'none')); + $pu_ht = GETPOST('price_ht'); $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); $qty = GETPOST('qty'); - $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); + $pu_ht_devise = GETPOST('multicurrency_subprice'); // Define info_bits $info_bits = 0; @@ -2255,21 +2330,23 @@ if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->situation_cycle_ref > 0) { - // in case of situation credit note - if (GETPOST('progress') >= 0) - { - $mesg = $langs->trans("CantBeNullOrPositive"); - setEventMessages($mesg, null, 'warnings'); - $error++; - $result = -1; - } elseif (GETPOST('progress') < $line->situation_percent) // TODO : use a modified $line->get_prev_progress($object->id) result - { - $mesg = $langs->trans("CantBeLessThanMinPercent"); - setEventMessages($mesg, null, 'warnings'); - $error++; - $result = -1; - } - } elseif (GETPOST('progress') < $percent) + // in case of situation credit note + if (GETPOST('progress') >= 0) + { + $mesg = $langs->trans("CantBeNullOrPositive"); + setEventMessages($mesg, null, 'warnings'); + $error++; + $result = -1; + } + elseif (GETPOST('progress') < $line->situation_percent) // TODO : use a modified $line->get_prev_progress($object->id) result + { + $mesg = $langs->trans("CantBeLessThanMinPercent"); + setEventMessages($mesg, null, 'warnings'); + $error++; + $result = -1; + } + } + elseif (GETPOST('progress') < $percent) { $mesg = '<div class="warning">'.$langs->trans("CantBeLessThanMinPercent").'</div>'; setEventMessages($mesg, null, 'warnings'); @@ -2324,7 +2401,9 @@ setEventMessages($langs->trans("ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv("UnitPriceHT"), $langs->transnoentitiesnoconv("CustomerAbsoluteDiscountShort")), null, 'errors'); } $error++; - } else { + } + else + { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); $error++; } @@ -2346,10 +2425,10 @@ } } - $result = $object->updateline(GETPOST('lineid', 'int'), $description, $pu_ht, $qty, price2num(GETPOST('remise_percent', 'alpha')), + $result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty, GETPOST('remise_percent'), $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type, - GETPOST('fk_parent_line', 'int'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, price2num(GETPOST('progress', 'alpha')), - GETPOST('units', 'alpha'), $pu_ht_devise); + GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('progress'), + $_POST['units'], $pu_ht_devise); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -2367,7 +2446,7 @@ } $ret = $object->fetch($id); // Reload to get new records - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } unset($_POST['qty']); @@ -2409,31 +2488,38 @@ setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'updatealllines' && $usercancreate && $_POST['all_percent'] == $langs->trans('Modifier')) // Update all lines of situation invoice + } + + elseif ($action == 'updatealllines' && $usercancreate && $_POST['all_percent'] == $langs->trans('Modifier')) // Update all lines of situation invoice { if (!$object->fetch($id) > 0) dol_print_error($db); if (GETPOST('all_progress') != "") { - $all_progress = GETPOST('all_progress', 'int'); + $all_progress = GETPOST('all_progress', 'int'); foreach ($object->lines as $line) { $percent = $line->get_prev_progress($object->id); if (floatval($all_progress) < floatval($percent)) { - $mesg = $langs->trans("Line").' '.$i.' : '.$langs->trans("CantBeLessThanMinPercent"); - setEventMessages($mesg, null, 'warnings'); + $mesg = $langs->trans("Line").' '.$i.' : '.$langs->trans("CantBeLessThanMinPercent"); + setEventMessages($mesg, null, 'warnings'); $result = -1; - } else $object->update_percent($line, $_POST['all_progress']); - } - } - } elseif ($action == 'updateline' && $usercancreate && $_POST['cancel'] == $langs->trans("Cancel")) { + } else + $object->update_percent($line, $_POST['all_progress']); + } + } + } + + elseif ($action == 'updateline' && $usercancreate && $_POST['cancel'] == $langs->trans('Cancel')) { header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); // To show again edited page exit(); - } // Outing situation invoice from cycle + } + + // Outing situation invoice from cycle elseif ($action == 'confirm_situationout' && $confirm == 'yes' && $usercancreate) { - $object->fetch($id, '', '', '', true); - - if (in_array($object->statut, array(Facture::STATUS_CLOSED, Facture::STATUS_VALIDATED)) + $object->fetch($id, '', '', '', true); + + if ($object->statut == Facture::STATUS_VALIDATED && $object->type == Facture::TYPE_SITUATION && $usercancreate && !$objectidnext @@ -2450,173 +2536,186 @@ $lastSituationCounter = $object->situation_counter; $linkedCreditNotesList = array(); - if (count($object->tab_next_situation_invoice) > 0) { - foreach ($object->tab_next_situation_invoice as $next_invoice) { - if ($next_invoice->type == Facture::TYPE_CREDIT_NOTE - && $next_invoice->situation_counter == $object->situation_counter - && $next_invoice->fk_facture_source == $object->id - ) - { - $linkedCreditNotesList[] = $next_invoice->id; - } - } - } - - $object->situation_cycle_ref = $newCycle; - $object->situation_counter = 1; - $object->situation_final = 0; - if ($object->update($user) > 0) - { - $errors = 0; - if (count($linkedCreditNotesList) > 0) - { - // now, credit note must follow - $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture '; - $sql .= ' SET situation_cycle_ref='.$newCycle; - $sql .= ' , situation_final=0'; - $sql .= ' , situation_counter='.$object->situation_counter; - $sql .= ' WHERE rowid IN ('.implode(',', $linkedCreditNotesList).')'; - - $resql = $db->query($sql); - if (!$resql) $errors++; - - // Change each progression persent on each lines - foreach ($object->lines as $line) - { - // no traitement for special product - if ($line->product_type == 9) continue; - - - if (!empty($object->tab_previous_situation_invoice)) - { - // search the last invoice in cycle - $lineIndex = count($object->tab_previous_situation_invoice) - 1; - $searchPreviousInvoice = true; - while ($searchPreviousInvoice) - { - if ($object->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1) - { - $searchPreviousInvoice = false; // find, exit; - break; - } else { - $lineIndex--; // go to previous invoice in cycle - } - } - - - $maxPrevSituationPercent = 0; - foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) - { - if ($prevLine->id == $line->fk_prev_id) - { - $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent); - } - } - - - $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent; - - if ($line->update() < 0) $errors++; - } - } - } - - if (!$errors) - { - setEventMessages($langs->trans('Updated'), '', 'mesgs'); - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - } else { - setEventMessages($langs->trans('ErrorOutingSituationInvoiceCreditNote'), array(), 'errors'); - } - } else { - setEventMessages($langs->trans('ErrorOutingSituationInvoiceOnUpdate'), array(), 'errors'); - } - } else { - setEventMessages($langs->trans('ErrorFindNextSituationInvoice'), array(), 'errors'); - } - } - } // add lines from objectlinked + if (count($object->tab_next_situation_invoice) > 0) { + foreach ($object->tab_next_situation_invoice as $next_invoice) { + if ($next_invoice->type == Facture::TYPE_CREDIT_NOTE + && $next_invoice->situation_counter == $object->situation_counter + && $next_invoice->fk_facture_source == $object->id + ) + { + $linkedCreditNotesList[] = $next_invoice->id; + } + } + } + + $object->situation_cycle_ref = $newCycle; + $object->situation_counter = 1; + $object->situation_final = 0; + if ($object->update($user) > 0) + { + $errors = 0; + if (count($linkedCreditNotesList) > 0) + { + // now, credit note must follow + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture '; + $sql .= ' SET situation_cycle_ref='.$newCycle; + $sql .= ' , situation_final=0'; + $sql .= ' , situation_counter='.$object->situation_counter; + $sql .= ' WHERE rowid IN ('.implode(',', $linkedCreditNotesList).')'; + + $resql = $db->query($sql); + if (!$resql) $errors++; + + // Change each progression persent on each lines + foreach ($object->lines as $line) + { + // no traitement for special product + if ($line->product_type == 9) continue; + + + if (!empty($object->tab_previous_situation_invoice)) + { + // search the last invoice in cycle + $lineIndex = count($object->tab_previous_situation_invoice) - 1; + $searchPreviousInvoice = true; + while ($searchPreviousInvoice) + { + if ($object->tab_previous_situation_invoice[$lineIndex]->type == Facture::TYPE_SITUATION || $lineIndex < 1) + { + $searchPreviousInvoice = false; // find, exit; + break; + } + else + { + $lineIndex--; // go to previous invoice in cycle + } + } + + + $maxPrevSituationPercent = 0; + foreach ($object->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) + { + if ($prevLine->id == $line->fk_prev_id) + { + $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent); + } + } + + + $line->situation_percent = $line->situation_percent - $maxPrevSituationPercent; + + if ($line->update() < 0) $errors++; + } + } + } + + if (!$errors) + { + setEventMessages($langs->trans('Updated'), '', 'mesgs'); + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + } + else + { + setEventMessages($langs->trans('ErrorOutingSituationInvoiceCreditNote'), array(), 'errors'); + } + } + else + { + setEventMessages($langs->trans('ErrorOutingSituationInvoiceOnUpdate'), array(), 'errors'); + } + } + else + { + setEventMessages($langs->trans('ErrorFindNextSituationInvoice'), array(), 'errors'); + } + } + } + + // add lines from objectlinked elseif ($action == 'import_lines_from_object' - && $usercancreate - && $object->statut == Facture::STATUS_DRAFT - && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION)) - { - $fromElement = GETPOST('fromelement'); - $fromElementid = GETPOST('fromelementid'); - $importLines = GETPOST('line_checkbox'); - - if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) - { - if ($fromElement == 'commande') - { - dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); - $lineClassName = 'OrderLine'; - } elseif ($fromElement == 'propal') - { - dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); - $lineClassName = 'PropaleLigne'; - } - $nextRang = count($object->lines) + 1; - $importCount = 0; - $error = 0; - foreach ($importLines as $lineId) - { - $lineId = intval($lineId); - $originLine = new $lineClassName($db); - if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) - { - $originLine->fetch_optionals(); - $desc = $originLine->desc; - $pu_ht = $originLine->subprice; - $qty = $originLine->qty; - $txtva = $originLine->tva_tx; - $txlocaltax1 = $originLine->localtax1_tx; - $txlocaltax2 = $originLine->localtax2_tx; - $fk_product = $originLine->fk_product; - $remise_percent = $originLine->remise_percent; - $date_start = $originLine->date_start; - $date_end = $originLine->date_end; - $ventil = 0; - $info_bits = $originLine->info_bits; - $fk_remise_except = $originLine->fk_remise_except; - $price_base_type = 'HT'; - $pu_ttc = 0; - $type = $originLine->product_type; - $rang = $nextRang++; - $special_code = $originLine->special_code; - $origin = $originLine->element; - $origin_id = $originLine->id; - $fk_parent_line = 0; - $fk_fournprice = $originLine->fk_fournprice; - $pa_ht = $originLine->pa_ht; - $label = $originLine->label; - $array_options = $originLine->array_options; - if ($object->type == Facture::TYPE_SITUATION) { - $situation_percent = 0; - } else { - $situation_percent = 100; - } - $fk_prev_id = ''; - $fk_unit = $originLine->fk_unit; - $pu_ht_devise = $originLine->multicurrency_subprice; - - $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $ventil, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $type, $rang, $special_code, $origin, $origin_id, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $situation_percent, $fk_prev_id, $fk_unit, $pu_ht_devise); - - if ($res > 0) { - $importCount++; - } else { - $error++; - } - } else { - $error++; - } - } - - if ($error) - { - setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); - } - } + && $usercancreate + && $object->statut == Facture::STATUS_DRAFT + && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION)) + { + $fromElement = GETPOST('fromelement'); + $fromElementid = GETPOST('fromelementid'); + $importLines = GETPOST('line_checkbox'); + + if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) + { + if ($fromElement == 'commande') + { + dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); + $lineClassName = 'OrderLine'; + } + elseif ($fromElement == 'propal') + { + dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); + $lineClassName = 'PropaleLigne'; + } + $nextRang = count($object->lines) + 1; + $importCount = 0; + $error = 0; + foreach ($importLines as $lineId) + { + $lineId = intval($lineId); + $originLine = new $lineClassName($db); + if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) + { + $originLine->fetch_optionals(); + $desc = $originLine->desc; + $pu_ht = $originLine->subprice; + $qty = $originLine->qty; + $txtva = $originLine->tva_tx; + $txlocaltax1 = $originLine->localtax1_tx; + $txlocaltax2 = $originLine->localtax2_tx; + $fk_product = $originLine->fk_product; + $remise_percent = $originLine->remise_percent; + $date_start = $originLine->date_start; + $date_end = $originLine->date_end; + $ventil = 0; + $info_bits = $originLine->info_bits; + $fk_remise_except = $originLine->fk_remise_except; + $price_base_type = 'HT'; + $pu_ttc = 0; + $type = $originLine->product_type; + $rang = $nextRang++; + $special_code = $originLine->special_code; + $origin = $originLine->element; + $origin_id = $originLine->id; + $fk_parent_line = 0; + $fk_fournprice = $originLine->fk_fournprice; + $pa_ht = $originLine->pa_ht; + $label = $originLine->label; + $array_options = $originLine->array_options; + if ($object->type == Facture::TYPE_SITUATION) { + $situation_percent = 0; + } + else { + $situation_percent = 100; + } + $fk_prev_id = ''; + $fk_unit = $originLine->fk_unit; + $pu_ht_devise = $originLine->multicurrency_subprice; + + $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $ventil, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $type, $rang, $special_code, $origin, $origin_id, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $situation_percent, $fk_prev_id, $fk_unit, $pu_ht_devise); + + if ($res > 0) { + $importCount++; + } else { + $error++; + } + } + else { + $error++; + } + } + + if ($error) + { + setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); + } + } } // Actions when printing a doc from card @@ -2640,7 +2739,7 @@ $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (!$error) @@ -2664,8 +2763,7 @@ if ($result > 0 && $id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); } if ($result >= 0) { @@ -2821,7 +2919,9 @@ //Replicate extrafields $expesrc->fetch_optionals(); $object->array_options = $expesrc->array_options; - } else { + } + else + { $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0)); $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0)); @@ -2839,7 +2939,9 @@ $object->array_options = $objectsrc->array_options; } } - } else { + } + else + { $cond_reglement_id = $soc->cond_reglement_id; $mode_reglement_id = $soc->mode_reglement_id; $fk_account = $soc->fk_account; @@ -2850,21 +2952,12 @@ if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code; } - // when payment condition is empty (means not override by payment condition form a other object, like third-party), try to use default value - if (empty($cond_reglement_id)) { - $cond_reglement_id = GETPOST("cond_reglement_id"); - } - - // when payment mode is empty (means not override by payment mode form a other object, like third-party), try to use default value - if (empty($mode_reglement_id)) { - $mode_reglement_id = GETPOST("mode_reglement_id"); - } - if (!empty($soc->id)) $absolute_discount = $soc->getAvailableDiscounts(); $note_public = $object->getDefaultCreateValueFor('note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTURE_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_public : null)); $note_private = $object->getDefaultCreateValueFor('note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTURE_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_private : null)); - if (!empty($conf->use_javascript_ajax)) { + if (!empty($conf->use_javascript_ajax)) + { require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; print ajax_combobox('fac_replacement'); print ajax_combobox('fac_avoir'); @@ -2878,26 +2971,24 @@ $text .= ' '.$langs->trans("ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv("MenuFinancial"), $langs->transnoentitiesnoconv("BillsCustomers"), $langs->transnoentitiesnoconv("ListOfTemplates")); if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) { - $text .= ' '.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')); + $text .= ' '.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')); } print info_admin($text, 0, 0, 0).'<br>'; } - print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST" id="formtocreate" name="formtocreate">'; + print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="POST">'; print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="action" value="add">'; if ($soc->id > 0) print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n"; print '<input name="ref" type="hidden" value="provisoire">'; print '<input name="ref_client" type="hidden" value="'.$ref_client.'">'; - print '<input name="force_cond_reglement_id" type="hidden" value="0">'; - print '<input name="force_mode_reglement_id" type="hidden" value="0">'; - print '<input name="force_fk_account" type="hidden" value="0">'; + print '<input name="ref_int" type="hidden" value="'.$ref_int.'">'; print '<input type="hidden" name="origin" value="'.$origin.'">'; print '<input type="hidden" name="originid" value="'.$originid.'">'; print '<input type="hidden" name="originentity" value="'.GETPOST('originentity').'">'; if (!empty($currency_tx)) print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.'">'; - print dol_get_fiche_head(''); + dol_fiche_head(''); print '<table class="border centpercent">'; @@ -2932,28 +3023,21 @@ print ')'; print '</td>'; print '</tr>'."\n"; - } else { + } + else + { print '<tr><td class="fieldrequired">'.$langs->trans('Customer').'</td>'; print '<td colspan="2">'; - print img_picto('', 'company').$form->select_company($soc->id, 'socid', '((s.client = 1 OR s.client = 3) AND s.status=1)', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); - // Option to reload page to retrieve customer informations. - if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) + print $form->select_company($soc->id, 'socid', '((s.client = 1 OR s.client = 3) AND s.status=1)', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); + // Option to reload page to retrieve customer informations. Note, this clear other input + if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE)) { print '<script type="text/javascript"> $(document).ready(function() { $("#socid").change(function() { - /* - console.log("Submit page"); - $(\'input[name="action"]\').val(\'create\'); - $(\'input[name="force_cond_reglement_id"]\').val(\'1\'); - $(\'input[name="force_mode_reglement_id"]\').val(\'1\'); - $(\'input[name="force_fk_account"]\').val(\'1\'); - $("#formtocreate").submit(); */ - - // For company change, we must reuse data of comany, not input already done, so we call a GET with action=create, not a POST submit. - console.log("We have changed the company - Reload page"); var socid = $(this).val(); var fac_rec = $(\'#fac_rec\').val(); + // reload page window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec; }); }); @@ -3010,15 +3094,15 @@ } print '</select>'; // Option to reload page to retrieve customer informations. Note, this clear other input - if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) + if (!empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE)) { print '<script type="text/javascript"> $(document).ready(function() { $("#fac_rec").change(function() { - console.log("We have changed the template invoice - Reload page"); + console.log("We changed the template invoice"); var fac_rec = $(this).val(); var socid = $(\'#socid\').val(); - // For template invoice change, we must reuse data of template, not input already done, so we call a GET with action=create, not a POST submit. + // reload page window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec; }); }); @@ -3095,10 +3179,10 @@ print '</div></div>'; // Next situation invoice - $opt = $form->selectSituationInvoices(GETPOST('originid', 'int'), $socid); + $opt = $form->selectSituationInvoices(GETPOST('originid'), $socid); print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; - $tmp = '<input type="radio" name="type" value="5"'.(GETPOST('type') == 5 && GETPOST('originid', 'int') ? ' checked' : ''); + $tmp = '<input type="radio" name="type" value="5"'.(GETPOST('type') == 5 && GETPOST('originid') ? ' checked' : ''); if ($opt == ('<option value ="0" selected>'.$langs->trans('NoSituations').'</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) $tmp .= ' disabled'; $tmp .= '> '; @@ -3164,27 +3248,29 @@ print $desc; print '</div></div>'; } - } else { - if (!empty($conf->global->INVOICE_USE_SITUATION)) - { - print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; - $tmp = '<input type="radio" name="type" id="radio_situation" value="0" disabled> '; - $text = '<label>'.$tmp.$langs->trans("InvoiceFirstSituationAsk").'</label> '; - $text .= '<span class="opacitymedium">('.$langs->trans("YouMustCreateInvoiceFromThird").')</span> '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3); - print $desc; - print '</div></div>'; - - print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; - $tmp = '<input type="radio" name="type" id="radio_situation" value="0" disabled> '; - $text = '<label>'.$tmp.$langs->trans("InvoiceSituationAsk").'</label> '; - $text .= '<span class="opacitymedium">('.$langs->trans("YouMustCreateInvoiceFromThird").')</span> '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3); - print $desc; - print '</div></div>'; - } - - print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; + } + else + { + if (!empty($conf->global->INVOICE_USE_SITUATION)) + { + print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; + $tmp = '<input type="radio" name="type" id="radio_situation" value="0" disabled> '; + $text = '<label>'.$tmp.$langs->trans("InvoiceFirstSituationAsk").'</label> '; + $text .= '<span class="opacitymedium">('.$langs->trans("YouMustCreateInvoiceFromThird").')</span> '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3); + print $desc; + print '</div></div>'; + + print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; + $tmp = '<input type="radio" name="type" id="radio_situation" value="0" disabled> '; + $text = '<label>'.$tmp.$langs->trans("InvoiceSituationAsk").'</label> '; + $text .= '<span class="opacitymedium">('.$langs->trans("YouMustCreateInvoiceFromThird").')</span> '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3); + print $desc; + print '</div></div>'; + } + + print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; $tmp = '<input type="radio" name="type" id="radio_replacement" value="0" disabled> '; $text = '<label>'.$tmp.$langs->trans("InvoiceReplacement").'</label> '; $text .= '<span class="opacitymedium">('.$langs->trans("YouMustCreateInvoiceFromThird").')</span> '; @@ -3267,9 +3353,11 @@ print '<br> <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="$(\'#credit_note_options input[type=checkbox]\').not(this).prop(\'checked\', false);" '.(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') > 0 ? 'checked' : '').' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>"; print '</div>'; - print '</div></div>'; - } - } else { + print '</div></div>'; + } + } + else + { print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">'; if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) $tmp = '<input type="radio" name="type" id="radio_creditnote" value="0" disabled> '; else $tmp = '<input type="radio" name="type" id="radio_creditnote" value="2" > '; @@ -3295,17 +3383,17 @@ if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) // Hidden conf { - // Add auto select default document model - $listtType = array(Facture::TYPE_STANDARD, Facture::TYPE_REPLACEMENT, Facture::TYPE_CREDIT_NOTE, Facture::TYPE_DEPOSIT, Facture::TYPE_SITUATION); - $jsListType = ''; - foreach ($listtType as $type) - { - $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; - $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; - $jsListType .= (!empty($jsListType) ? ',' : '').'"'.$type.'":"'.$curent.'"'; - } - - print '<script type="text/javascript" language="javascript"> + // Add auto select default document model + $listtType = array(Facture::TYPE_STANDARD, Facture::TYPE_REPLACEMENT, Facture::TYPE_CREDIT_NOTE, Facture::TYPE_DEPOSIT, Facture::TYPE_SITUATION); + $jsListType = ''; + foreach ($listtType as $type) + { + $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; + $curent = !empty($conf->global->{$thisTypeConfName}) ? $conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; + $jsListType .= (!empty($jsListType) ? ',' : '').'"'.$type.'":"'.$curent.'"'; + } + + print '<script type="text/javascript" language="javascript"> $(document).ready(function() { var listType = {'.$jsListType.'}; $("[name=\'type\'").change(function() { @@ -3409,34 +3497,31 @@ } }); - $("[name=\'type\']:checked").trigger("change"); + $("[name=\'type\']").trigger("change"); }); </script>'; } // Payment mode print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">'; - $form->select_types_paiements(GETPOSTISSET('mode_reglement_id') ? GETPOST('mode_reglement_id') : $mode_reglement_id, 'mode_reglement_id', 'CRDT'); + $form->select_types_paiements(isset($_POST['mode_reglement_id']) ? $_POST['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id', 'CRDT'); print '</td></tr>'; // Bank Account - if (!empty($conf->banque->enabled)) - { - if (GETPOSTISSET('fk_account')) { - $fk_account = GETPOST('fk_account', 'int'); - } - - print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">'; - print img_picto('', 'bank_account', 'class="paddingrightonly"').$form->select_comptes($fk_account, 'fk_account', 0, '', 1, '', 0, '', 1); - print '</td></tr>'; - } + if (GETPOSTISSET('fk_account')) { + $fk_account = GETPOST('fk_account'); + } + + print '<tr><td>'.$langs->trans('BankAccount').'</td><td colspan="2">'; + $form->select_comptes($fk_account, 'fk_account', 0, '', 1); + print '</td></tr>'; // Project if (!empty($conf->projet->enabled)) { $langs->load('projects'); print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">'; - print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500'); + $numprojet = $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth500'); print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id.($fac_rec ? '&fac_rec='.$fac_rec : '')).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>'; print '</td></tr>'; } @@ -3463,7 +3548,7 @@ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook)) { - if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE) && !empty($soc->id)) { + if (!empty($conf->global->THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE)) { // copy from thirdparty $tpExtrafields = new Extrafields($db); $tpExtrafieldLabels = $tpExtrafields->fetch_name_optionals_label($soc->table_element); @@ -3482,12 +3567,12 @@ $liste = ModelePDFFactures::liste_modeles($db); if (!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) { // Hidden conf - $paramkey = 'FACTURE_ADDON_PDF_'.$object->type; - $preselected = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF; + $paramkey = 'FACTURE_ADDON_PDF_'.$object->type; + $curent = !empty($conf->global->$paramkey) ? $conf->global->$paramkey : $conf->global->FACTURE_ADDON_PDF; } else { - $preselected = $conf->global->FACTURE_ADDON_PDF; - } - print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', '', 1); + $curent = $conf->global->FACTURE_ADDON_PDF; + } + print $form->selectarray('model', $liste, $curent); print "</td></tr>"; // Multicurrency @@ -3551,7 +3636,7 @@ print '</td></tr>'; } - // Lines from source (TODO Show them also when creating invoice from template invoice) + // Lines from source (TODO Show them also when creating invoice from tempalte invoice) if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { // TODO for compatibility @@ -3596,7 +3681,7 @@ if (is_array($objectsrc->linkedObjects['facture']) && count($objectsrc->linkedObjects['facture']) >= 1) { setEventMessages('WarningBillExist', null, 'warnings'); - echo ' ('.$langs->trans('LatestRelatedBill').' '.end($objectsrc->linkedObjects['facture'])->getNomUrl(1).')'; + echo ' ('.$langs->trans('LatestRelatedBill').end($objectsrc->linkedObjects['facture'])->getNomUrl(1).')'; } echo '</td></tr>'; print '<tr><td>'.$langs->trans('AmountHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>'; @@ -3622,14 +3707,16 @@ print "</table>\n"; - print dol_get_fiche_end(); + dol_fiche_end(); // Button "Create Draft" print '<div class="center">'; print '<input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'">'; print ' '; - print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">'; + print '<input type="button" class="button" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">'; print '</div>'; + + print "</form>\n"; // Show origin lines if (!empty($origin) && !empty($originid) && is_object($objectsrc)) { @@ -3640,13 +3727,15 @@ print '<table class="noborder centpercent">'; - $objectsrc->printOriginLinesList('', $selectedLines); + $objectsrc->printOriginLinesList(); print '</table>'; } - print '</form>'; -} elseif ($id > 0 || !empty($ref)) { + print '<br>'; +} +elseif ($id > 0 || !empty($ref)) +{ /* * Show object in view mode */ @@ -3711,7 +3800,7 @@ $head = facture_prepare_head($object); - print dol_get_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'), -1, 'bill'); + dol_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'), -1, 'bill'); $formconfirm = ''; @@ -3754,7 +3843,9 @@ array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1, 0, 0, $langs->trans("NoStockAction"), 0, $forcecombo)) ); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', $formquestion, "yes", 1); - } else { + } + else + { $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', 'no', 1); } } else { @@ -3768,7 +3859,7 @@ $label = $langs->trans("ConfirmOuting"); $formquestion = array(); // remove situation from cycle - if (in_array($object->statut, array(Facture::STATUS_CLOSED, Facture::STATUS_VALIDATED)) + if ($object->statut == Facture::STATUS_VALIDATED && $usercancreate && !$objectidnext && $object->is_last_in_cycle() @@ -3892,7 +3983,6 @@ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', "yes", 1); } if ($action == 'paid' && $resteapayer > 0) { - $close = array(); // Code $i = 0; $close[$i]['code'] = 'discount_vat'; // escompte @@ -3919,7 +4009,7 @@ $i++; // arrayreasons[code]=reason foreach ($close as $key => $val) { - $arrayreasons[$close[$key]['code']] = $close[$key]['reason']; + $arrayreasons[$close [$key]['code']] = $close[$key]['reason']; } // Cree un tableau formulaire @@ -3960,7 +4050,7 @@ } } - if ($action == 'deletepayment') + if ($action == 'deletepaiement') { $payment_id = GETPOST('paiement_id'); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&paiement_id='.$payment_id, $langs->trans('DeletePayment'), $langs->trans('ConfirmDeletePayment'), 'confirm_delete_paiement', '', 'no', 1); @@ -3977,7 +4067,7 @@ // 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()) ); // Ask confirmatio 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); @@ -4070,31 +4160,30 @@ // Type print '<tr><td class="titlefield fieldname_type">'.$langs->trans('Type').'</td><td class="valuefield fieldname_type">'; - print '<span class="badgeneutral">'; print $object->getLibType(); - print '</span>'; if ($object->module_source) { - print ' <span class="opacitymediumbycolor paddingleft">('.$langs->trans("POS").' '.ucfirst($object->module_source).' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>'; + print ' <span class="opacitymediumbycolor">('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>'; } if ($object->type == Facture::TYPE_REPLACEMENT) { $facreplaced = new Facture($db); $facreplaced->fetch($object->fk_facture_source); - print ' <span class="opacitymediumbycolor paddingleft">('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')</span>'; + print ' <span class="opacitymediumbycolor">('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')</span>'; } if ($object->type == Facture::TYPE_CREDIT_NOTE && !empty($object->fk_facture_source)) { $facusing = new Facture($db); $facusing->fetch($object->fk_facture_source); - print ' <span class="opacitymediumbycolor paddingleft">('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')</span>'; + print ' <span class="opacitymediumbycolor">('.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).')</span>'; } $facidavoir = $object->getListIdAvoirFromInvoice(); if (count($facidavoir) > 0) { - print ' <span class="opacitymediumbycolor paddingleft">('.$langs->transnoentities("InvoiceHasAvoir"); + print ' <span class="opacitymediumbycolor">('.$langs->transnoentities("InvoiceHasAvoir"); $i = 0; foreach ($facidavoir as $id) { if ($i == 0) print ' '; - else print ','; + else + print ','; $facavoir = new Facture($db); $facavoir->fetch($id); print $facavoir->getNomUrl(1); @@ -4104,19 +4193,14 @@ if ($objectidnext > 0) { $facthatreplace = new Facture($db); $facthatreplace->fetch($objectidnext); - print ' <span class="opacitymediumbycolor paddingleft">('.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).')</span>'; + print ' <span class="opacitymediumbycolor">('.$langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)).')</span>'; } if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { $discount = new DiscountAbsolute($db); $result = $discount->fetch(0, $object->id); if ($result > 0) { - print ' <span class="opacitymediumbycolor paddingleft">'; - $s = $langs->trans("CreditNoteConvertedIntoDiscount", '{s1}', '{s2}'); - $s = str_replace('{s1}', $object->getLibType(1), $s); - $s = str_replace('{s2}', $discount->getNomUrl(1, 'discount'), $s); - print $s; - print '</span><br>'; + print '. <span class="opacitymediumbycolor">'.$langs->trans("CreditNoteConvertedIntoDiscount", $object->getLibType(1), $discount->getNomUrl(1, 'discount')).'</span><br>'; } } @@ -4125,11 +4209,10 @@ $tmptemplate = new FactureRec($db); $result = $tmptemplate->fetch($object->fk_fac_rec_source); if ($result > 0) { - print ' <span class="opacitymediumbycolor paddingleft">'; - $s = $langs->transnoentities("GeneratedFromTemplate", '{s1}'); - $s = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$tmptemplate->id.'">'.dol_escape_htmltag($tmptemplate->ref).'</a>', $s); - print $s; - print '</span>'; + print '. <span class="opacitymediumbycolor">'.$langs->trans( + "GeneratedFromTemplate", + '<a href="'.DOL_MAIN_URL_ROOT.'/compta/facture/card-rec.php?facid='.$tmptemplate->id.'">'.$tmptemplate->ref.'</a>' + ).'</span>'; } } print '</td></tr>'; @@ -4137,11 +4220,13 @@ // Relative and absolute discounts print '<!-- Discounts -->'."\n"; print '<tr><td>'.$langs->trans('Discounts'); + print '</td><td>'; $thirdparty = $soc; $discount_type = 0; $backtopage = urlencode($_SERVER["PHP_SELF"].'?facid='.$object->id); include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php'; + print '</td></tr>'; // Date invoice @@ -4149,15 +4234,19 @@ print '<table class="nobordernopadding" width="100%"><tr><td>'; print $langs->trans('DateInvoice'); print '</td>'; - if ($action != 'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&facid='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>'; print '</tr></table>'; print '</td><td>'; - if ($action == 'editinvoicedate') { - $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date, 'invoicedate'); + if ($object->type != Facture::TYPE_CREDIT_NOTE) { + if ($action == 'editinvoicedate') { + $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date, 'invoicedate'); + } else { + print dol_print_date($object->date, 'day'); + } } else { - print '<span class="valuedate">'.dol_print_date($object->date, 'day').'</span>'; + print dol_print_date($object->date, 'day'); } print '</td>'; @@ -4176,7 +4265,7 @@ if ($action == 'editdate_pointoftax') { $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_pointoftax, 'date_pointoftax'); } else { - print '<span class="valuedate">'.dol_print_date($object->date_pointoftax, 'day').'</span>'; + print dol_print_date($object->date_pointoftax, 'day'); } print '</td></tr>'; } @@ -4216,7 +4305,7 @@ if ($action == 'editpaymentterm') { $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_lim_reglement, 'paymentterm'); } else { - print '<span class="valuedate">'.dol_print_date($object->date_lim_reglement, 'day').'</span>'; + print dol_print_date($object->date_lim_reglement, 'day'); if ($object->hasDelay()) { print img_warning($langs->trans('Late')); } @@ -4238,7 +4327,9 @@ if ($action == 'editmode') { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); - } else { + } + else + { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none', 'CRDT'); } print '</td></tr>'; @@ -4290,25 +4381,24 @@ } // Bank Account - if (!empty($conf->banque->enabled)) - { - print '<tr><td class="nowrap">'; - print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; - print $langs->trans('BankAccount'); - print '<td>'; - if (($action != 'editbankaccount') && $usercancreate) - print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>'; - print '</tr></table>'; - print '</td><td>'; - if ($action == 'editbankaccount') - { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); - } - print "</td>"; - print '</tr>'; - } + print '<tr><td class="nowrap">'; + print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; + print $langs->trans('BankAccount'); + print '<td>'; + if (($action != 'editbankaccount') && $usercancreate) + print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>'; + print '</tr></table>'; + print '</td><td>'; + if ($action == 'editbankaccount') + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } + else + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print "</td>"; + print '</tr>'; // Incoterms if (!empty($conf->incoterm->enabled)) @@ -4325,7 +4415,9 @@ if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); - } else { + } + else + { print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); } print '</td></tr>'; @@ -4334,102 +4426,108 @@ if (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) { - $displayWarranty = true; + $displayWarranty = true; if (!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)) { $displayWarranty = false; } - if ($displayWarranty) { + if($displayWarranty) { // Retained Warranty print '<tr class="retained-warranty-lines" ><td>'; print '<table id="retained-warranty-table" class="nobordernopadding" width="100%"><tr><td>'; print $langs->trans('RetainedWarranty'); print '</td>'; if ($action != 'editretainedwarranty' && $user->rights->facture->creer) { - print '<td align="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editretainedwarranty&facid='.$object->id.'">'.img_edit($langs->trans('setretainedwarranty'), 1).'</a></td>'; - } - - print '</tr></table>'; - print '</td><td>'; - if ($action == 'editretainedwarranty') - { - print '<form id="retained-warranty-form" method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">'; - print '<input type="hidden" name="action" value="setretainedwarranty">'; - print '<input type="hidden" name="token" value="'.newToken().'">'; - print '<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.'" >'; - print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; - print '</form>'; - } else { - print price($object->retained_warranty).'%'; - } - print '</td></tr>'; - - // Retained warranty payment term - print '<tr class="retained-warranty-lines" ><td>'; - print '<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>'; - print $langs->trans('PaymentConditionsShortRetainedWarranty'); - print '</td>'; - if ($action != 'editretainedwarrantypaymentterms' && $user->rights->facture->creer) { - print '<td align="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editretainedwarrantypaymentterms&facid='.$object->id.'">'.img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1).'</a></td>'; - } - - print '</tr></table>'; - print '</td><td>'; - $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); - if ($object->date > $defaultDate) { - $defaultDate = $object->date; - } - - if ($action == 'editretainedwarrantypaymentterms') - { - //date('Y-m-d',$object->date_lim_reglement) - print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">'; - print '<input type="hidden" name="action" value="setretainedwarrantyconditions">'; - print '<input type="hidden" name="token" value="'.newToken().'">'; - $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); - $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement; - $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; - $form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); - print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; - print '</form>'; - } else { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement, 'none'); - if (!$displayWarranty) { - print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle" '); - } - } - print '</td></tr>'; - - // Retained Warranty payment date limit - print '<tr class="retained-warranty-lines" ><td>'; - print '<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>'; - print $langs->trans('RetainedWarrantyDateLimit'); - print '</td>'; - if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer) { - print '<td align="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editretainedwarrantydatelimit&facid='.$object->id.'">'.img_edit($langs->trans('setretainedwarrantyDateLimit'), 1).'</a></td>'; - } - - print '</tr></table>'; - print '</td><td>'; - $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); - if ($object->date > $defaultDate) { - $defaultDate = $object->date; - } - - if ($action == 'editretainedwarrantydatelimit') - { - //date('Y-m-d',$object->date_lim_reglement) - print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">'; - print '<input type="hidden" name="action" value="setretainedwarrantydatelimit">'; - print '<input type="hidden" name="token" value="'.newToken().'">'; - print '<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date($object->date, '%Y-%m-%d').'" value="'.dol_print_date($defaultDate, '%Y-%m-%d').'" >'; - print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; - print '</form>'; - } else { - print dol_print_date($object->retained_warranty_date_limit, 'day'); - } - print '</td></tr>'; - } + print '<td align="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editretainedwarranty&facid='.$object->id.'">'.img_edit($langs->trans('setretainedwarranty'), 1).'</a></td>'; + } + + print '</tr></table>'; + print '</td><td>'; + if ($action == 'editretainedwarranty') + { + print '<form id="retained-warranty-form" method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">'; + print '<input type="hidden" name="action" value="setretainedwarranty">'; + print '<input type="hidden" name="token" value="'.newToken().'">'; + print '<input name="retained_warranty" type="number" step="0.01" min="0" max="100" value="'.$object->retained_warranty.'" >'; + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; + print '</form>'; + } + else + { + print price($object->retained_warranty).'%'; + } + print '</td></tr>'; + + // Retained warranty payment term + print '<tr class="retained-warranty-lines" ><td>'; + print '<table id="retained-warranty-cond-reglement-table" class="nobordernopadding" width="100%"><tr><td>'; + print $langs->trans('PaymentConditionsShortRetainedWarranty'); + print '</td>'; + if ($action != 'editretainedwarrantypaymentterms' && $user->rights->facture->creer) { + print '<td align="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editretainedwarrantypaymentterms&facid='.$object->id.'">'.img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1).'</a></td>'; + } + + print '</tr></table>'; + print '</td><td>'; + $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); + if ($object->date > $defaultDate) { + $defaultDate = $object->date; + } + + if ($action == 'editretainedwarrantypaymentterms') + { + //date('Y-m-d',$object->date_lim_reglement) + print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">'; + print '<input type="hidden" name="action" value="setretainedwarrantyconditions">'; + print '<input type="hidden" name="token" value="'.newToken().'">'; + $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement; + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; + $form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; + print '</form>'; + } + else + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->retained_warranty_fk_cond_reglement, 'none'); + if (!$displayWarranty) { + print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle" '); + } + } + print '</td></tr>'; + + // Retained Warranty payment date limit + print '<tr class="retained-warranty-lines" ><td>'; + print '<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>'; + print $langs->trans('RetainedWarrantyDateLimit'); + print '</td>'; + if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer) { + print '<td align="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editretainedwarrantydatelimit&facid='.$object->id.'">'.img_edit($langs->trans('setretainedwarrantyDateLimit'), 1).'</a></td>'; + } + + print '</tr></table>'; + print '</td><td>'; + $defaultDate = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : strtotime('-1 years', $object->date_lim_reglement); + if ($object->date > $defaultDate) { + $defaultDate = $object->date; + } + + if ($action == 'editretainedwarrantydatelimit') + { + //date('Y-m-d',$object->date_lim_reglement) + print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">'; + print '<input type="hidden" name="action" value="setretainedwarrantydatelimit">'; + print '<input type="hidden" name="token" value="'.newToken().'">'; + print '<input name="retained_warranty_date_limit" type="date" step="1" min="'.dol_print_date($object->date, '%Y-%m-%d').'" value="'.dol_print_date($defaultDate, '%Y-%m-%d').'" >'; + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; + print '</form>'; + } + else + { + print dol_print_date($object->retained_warranty_date_limit, 'day'); + } + print '</td></tr>'; + } } @@ -4443,50 +4541,44 @@ print '<div class="fichehalfright">'; print '<div class="ficheaddleft">'; - print '<!-- amounts -->'."\n"; print '<table class="border bordertop tableforfield centpercent">'; - - $sign = 1; - if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) { - $sign = -1; // We invert sign for output - } if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { // Multicurrency Amount HT print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>'; - print '<td class="nowrap amountcard">'.price($sign * $object->multicurrency_total_ht, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; + print '<td class="nowrap amountcard">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; print '</tr>'; // Multicurrency Amount VAT print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>'; - print '<td class="nowrap amountcard">'.price($sign * $object->multicurrency_total_tva, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; + print '<td class="nowrap amountcard">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; print '</tr>'; // Multicurrency Amount TTC print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>'; - print '<td class="nowrap amountcard">'.price($sign * $object->multicurrency_total_ttc, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; + print '<td class="nowrap amountcard">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; print '</tr>'; } // Amount print '<tr><td class="titlefieldmiddle">'.$langs->trans('AmountHT').'</td>'; - print '<td class="nowrap amountcard">'.price($sign * $object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<td class="nowrap amountcard">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; // Vat - print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="3" class="nowrap amountcard">'.price($sign * $object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<tr><td>'.$langs->trans('AmountVAT').'</td><td colspan="3" class="nowrap amountcard">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; print '</tr>'; // Amount Local Taxes if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1 { print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>'; - print '<td class="nowrap amountcard">'.price($sign * $object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<td class="nowrap amountcard">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; } if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2 { print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>'; - print '<td class=nowrap amountcard">'.price($sign * $object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<td class=nowrap amountcard">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; } // Revenue stamp @@ -4544,11 +4636,13 @@ } // Total with tax - print '<tr><td>'.$langs->trans('AmountTTC').'</td><td class="nowrap amountcard">'.price($sign * $object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<tr><td>'.$langs->trans('AmountTTC').'</td><td class="nowrap amountcard">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; print '</table>'; + $sign = 1; + if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1; $nbrows = 8; $nbcols = 3; if (!empty($conf->projet->enabled)) @@ -4571,84 +4665,84 @@ // List of previous situation invoices if (($object->situation_cycle_ref > 0) && !empty($conf->global->INVOICE_USE_SITUATION)) { - print '<table class="noborder situationstable" width="100%">'; - - - print '<tr class="liste_titre">'; - print '<td>'.$langs->trans('ListOfSituationInvoices').'</td>'; - print '<td></td>'; - print '<td class="center">'.$langs->trans('Situation').'</td>'; - if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; - print '<td class="right">'.$langs->trans('AmountHT').'</td>'; - print '<td class="right">'.$langs->trans('AmountTTC').'</td>'; - print '<td width="18"> </td>'; - print '</tr>'; - - - $total_prev_ht = $total_prev_ttc = 0; - $total_global_ht = $total_global_ttc = 0; - - if (count($object->tab_previous_situation_invoice) > 0) { - // List of previous invoices - - $current_situation_counter = array(); - foreach ($object->tab_previous_situation_invoice as $prev_invoice) { - $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement(); - $total_prev_ht += $prev_invoice->total_ht; - $total_prev_ttc += $prev_invoice->total_ttc; - $current_situation_counter[] = (($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter; - print '<tr class="oddeven">'; - print '<td>'.$prev_invoice->getNomUrl(1).'</td>'; - print '<td></td>'; - print '<td align="center" >'.(($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$prev_invoice->situation_counter.'</td>'; - if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; - print '<td class="right">'.price($prev_invoice->total_ht).'</td>'; - print '<td class="right">'.price($prev_invoice->total_ttc).'</td>'; - print '<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).'</td>'; - print '</tr>'; - } - } - - - $total_global_ht += $total_prev_ht; - $total_global_ttc += $total_prev_ttc; - $total_global_ht += $object->total_ht; - $total_global_ttc += $object->total_ttc; - $current_situation_counter[] = (($object->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $object->situation_counter; - print '<tr class="oddeven">'; - print '<td>'.$object->getNomUrl(1).'</td>'; - print '<td></td>'; - print '<td class="center">'.(($object->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$object->situation_counter.'</td>'; - if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; - print '<td class="right">'.price($object->total_ht).'</td>'; - print '<td class="right">'.price($object->total_ttc).'</td>'; - print '<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).'</td>'; - print '</tr>'; - - - print '<tr class="oddeven">'; - print '<td colspan="2" class="left"><b>'.$langs->trans('CurrentSituationTotal').'</b></td>'; - print '<td>'; - $i = 0; - foreach ($current_situation_counter as $sit) - { - $curSign = $sit > 0 ? '+' : '-'; - $curType = $sit > 0 ? $langs->trans('situationInvoiceShortcode_S') : $langs->trans('situationInvoiceShortcode_AS'); - if ($i > 0) print ' '.$curSign.' '; - print $curType.abs($sit); - $i++; - } - print '</td>'; - if (!empty($conf->banque->enabled)) print '<td></td>'; - print '<td class="right"><b>'.price($total_global_ht).'</b></td>'; - print '<td class="right"><b>'.price($total_global_ttc).'</b></td>'; - print '<td width="18"> </td>'; - print '</tr>'; - - - if (count($object->tab_next_situation_invoice) > 0) { - // List of next invoices - /*print '<tr class="liste_titre">'; + print '<table class="noborder situationstable" width="100%">'; + + + print '<tr class="liste_titre">'; + print '<td>'.$langs->trans('ListOfSituationInvoices').'</td>'; + print '<td></td>'; + print '<td class="center">'.$langs->trans('Situation').'</td>'; + if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; + print '<td class="right">'.$langs->trans('AmountHT').'</td>'; + print '<td class="right">'.$langs->trans('AmountTTC').'</td>'; + print '<td width="18"> </td>'; + print '</tr>'; + + + $total_prev_ht = $total_prev_ttc = 0; + $total_global_ht = $total_global_ttc = 0; + + if (count($object->tab_previous_situation_invoice) > 0) { + // List of previous invoices + + $current_situation_counter = array(); + foreach ($object->tab_previous_situation_invoice as $prev_invoice) { + $tmptotalpaidforthisinvoice = $prev_invoice->getSommePaiement(); + $total_prev_ht += $prev_invoice->total_ht; + $total_prev_ttc += $prev_invoice->total_ttc; + $current_situation_counter[] = (($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $prev_invoice->situation_counter; + print '<tr class="oddeven">'; + print '<td>'.$prev_invoice->getNomUrl(1).'</td>'; + print '<td></td>'; + print '<td align="center" >'.(($prev_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$prev_invoice->situation_counter.'</td>'; + if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; + print '<td class="right">'.price($prev_invoice->total_ht).'</td>'; + print '<td class="right">'.price($prev_invoice->total_ttc).'</td>'; + print '<td class="right">'.$prev_invoice->getLibStatut(3, $tmptotalpaidforthisinvoice).'</td>'; + print '</tr>'; + } + } + + + $total_global_ht += $total_prev_ht; + $total_global_ttc += $total_prev_ttc; + $total_global_ht += $object->total_ht; + $total_global_ttc += $object->total_ttc; + $current_situation_counter[] = (($object->type == Facture::TYPE_CREDIT_NOTE) ?-1 : 1) * $object->situation_counter; + print '<tr class="oddeven">'; + print '<td>'.$object->getNomUrl(1).'</td>'; + print '<td></td>'; + print '<td class="center">'.(($object->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$object->situation_counter.'</td>'; + if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; + print '<td class="right">'.price($object->total_ht).'</td>'; + print '<td class="right">'.price($object->total_ttc).'</td>'; + print '<td class="right">'.$object->getLibStatut(3, $object->getSommePaiement()).'</td>'; + print '</tr>'; + + + print '<tr class="oddeven">'; + print '<td colspan="2" class="left"><b>'.$langs->trans('CurrentSituationTotal').'</b></td>'; + print '<td>'; + $i = 0; + foreach ($current_situation_counter as $sit) + { + $curSign = $sit > 0 ? '+' : '-'; + $curType = $sit > 0 ? $langs->trans('situationInvoiceShortcode_S') : $langs->trans('situationInvoiceShortcode_AS'); + if ($i > 0) print ' '.$curSign.' '; + print $curType.abs($sit); + $i++; + } + print '</td>'; + if (!empty($conf->banque->enabled)) print '<td></td>'; + print '<td class="right"><b>'.price($total_global_ht).'</b></td>'; + print '<td class="right"><b>'.price($total_global_ttc).'</b></td>'; + print '<td width="18"> </td>'; + print '</tr>'; + + + if (count($object->tab_next_situation_invoice) > 0) { + // List of next invoices + /*print '<tr class="liste_titre">'; print '<td>' . $langs->trans('ListOfNextSituationInvoices') . '</td>'; print '<td></td>'; print '<td></td>'; @@ -4658,41 +4752,39 @@ print '<td width="18"> </td>'; print '</tr>';*/ - $total_next_ht = $total_next_ttc = 0; - - foreach ($object->tab_next_situation_invoice as $next_invoice) { - $totalpaye = $next_invoice->getSommePaiement(); - $total_next_ht += $next_invoice->total_ht; - $total_next_ttc += $next_invoice->total_ttc; - - print '<tr class="oddeven">'; - print '<td>'.$next_invoice->getNomUrl(1).'</td>'; - print '<td></td>'; - print '<td class="center">'.(($next_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$next_invoice->situation_counter.'</td>'; - if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; - print '<td class="right">'.price($next_invoice->total_ht).'</td>'; - print '<td class="right">'.price($next_invoice->total_ttc).'</td>'; - print '<td class="right">'.$next_invoice->getLibStatut(3, $totalpaye).'</td>'; - print '</tr>'; - } - - $total_global_ht += $total_next_ht; - $total_global_ttc += $total_next_ttc; - - print '<tr class="oddeven">'; - print '<td colspan="3" class="right"></td>'; - if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; - print '<td class="right"><b>'.price($total_global_ht).'</b></td>'; - print '<td class="right"><b>'.price($total_global_ttc).'</b></td>'; - print '<td width="18"> </td>'; - print '</tr>'; - } - - print '</table>'; - } - - $sign = 1; - if ($object->type == $object::TYPE_CREDIT_NOTE) $sign = -1; + $total_next_ht = $total_next_ttc = 0; + + foreach ($object->tab_next_situation_invoice as $next_invoice) { + $totalpaye = $next_invoice->getSommePaiement(); + $total_next_ht += $next_invoice->total_ht; + $total_next_ttc += $next_invoice->total_ttc; + + print '<tr class="oddeven">'; + print '<td>'.$next_invoice->getNomUrl(1).'</td>'; + print '<td></td>'; + print '<td class="center">'.(($next_invoice->type == Facture::TYPE_CREDIT_NOTE) ? $langs->trans('situationInvoiceShortcode_AS') : $langs->trans('situationInvoiceShortcode_S')).$next_invoice->situation_counter.'</td>'; + if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; + print '<td class="right">'.price($next_invoice->total_ht).'</td>'; + print '<td class="right">'.price($next_invoice->total_ttc).'</td>'; + print '<td class="right">'.$next_invoice->getLibStatut(3, $totalpaye).'</td>'; + print '</tr>'; + } + + $total_global_ht += $total_next_ht; + $total_global_ttc += $total_next_ttc; + + print '<tr class="oddeven">'; + print '<td colspan="3" class="right"></td>'; + if (!empty($conf->banque->enabled)) print '<td class="right"></td>'; + print '<td class="right"><b>'.price($total_global_ht).'</b></td>'; + print '<td class="right"><b>'.price($total_global_ttc).'</b></td>'; + print '<td width="18"> </td>'; + print '</tr>'; + } + + print '</table>'; + } + // List of payments already done @@ -4743,15 +4835,7 @@ print '<tr class="oddeven"><td>'; print $paymentstatic->getNomUrl(1); print '</td>'; - print '<td>'; - $dateofpayment = $db->jdate($objp->dp); - $tmparray = dol_getdate($dateofpayment); - if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it - print dol_print_date($dateofpayment, 'day'); - } else { // Hours was set to real date of payment (special case for POS for example) - print dol_print_date($dateofpayment, 'dayhour', 'tzuser'); - } - print '</td>'; + print '<td>'.dol_print_date($db->jdate($objp->dp), 'dayhour').'</td>'; $label = ($langs->trans("PaymentType".$objp->payment_code) != ("PaymentType".$objp->payment_code)) ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_label; print '<td>'.$label.' '.$objp->num_payment.'</td>'; if (!empty($conf->banque->enabled)) @@ -4778,7 +4862,7 @@ print '<td class="center">'; if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0) { - print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deletepayment&token='.newToken().'&paiement_id='.$objp->rowid.'">'; + print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deletepaiement&paiement_id='.$objp->rowid.'">'; print img_delete(); print '</a>'; } @@ -4799,13 +4883,11 @@ if ($object->type != Facture::TYPE_CREDIT_NOTE) { // Total already paid print '<tr><td colspan="'.$nbcols.'" class="right">'; - print '<span class="opacitymedium">'; - if ($object->type != Facture::TYPE_DEPOSIT) { + if ($object->type != Facture::TYPE_DEPOSIT) print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); - } else { + else print $langs->trans('AlreadyPaid'); - } - print '</span></td><td class="right'.(($totalpaye > 0) ? ' amountalreadypaid' : '').'">'.price($totalpaye).'</td><td> </td></tr>'; + print ' :</td><td class="right'.(($totalpaye > 0) ? ' amountalreadypaid' : '').'">'.price($totalpaye).'</td><td> </td></tr>'; $resteapayeraffiche = $resteapayer; $cssforamountpaymentcomplete = 'amountpaymentcomplete'; @@ -4826,14 +4908,12 @@ $obj = $db->fetch_object($resql); $invoice->fetch($obj->fk_facture_source); print '<tr><td colspan="'.$nbcols.'" class="right">'; - print '<span class="opacitymedium">'; if ($invoice->type == Facture::TYPE_CREDIT_NOTE) print $langs->trans("CreditNote").' '; if ($invoice->type == Facture::TYPE_DEPOSIT) print $langs->trans("Deposit").' '; print $invoice->getNomUrl(0); - print '</span>'; - print '</td>'; + print ' :</td>'; print '<td class="right">'.price($obj->amount_ttc).'</td>'; print '<td class="right">'; print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">'.img_delete().'</a>'; @@ -4851,9 +4931,7 @@ // Paye partiellement 'escompte' if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { print '<tr><td colspan="'.$nbcols.'" class="nowrap right">'; - print '<span class="opacitymedium">'; - print $form->textwithpicto($langs->trans("Discount"), $langs->trans("HelpEscompte"), - 1); - print '</span>'; + print $form->textwithpicto($langs->trans("Discount").':', $langs->trans("HelpEscompte"), - 1); print '</td><td class="right">'.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye, 'MT')).'</td><td> </td></tr>'; $resteapayeraffiche = 0; $cssforamountpaymentcomplete = 'amountpaymentneutral'; @@ -4861,9 +4939,7 @@ // Paye partiellement ou Abandon 'badcustomer' if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'badcustomer') { print '<tr><td colspan="'.$nbcols.'" class="nowrap right">'; - print '<span class="opacitymedium">'; - print $form->textwithpicto($langs->trans("Abandoned"), $langs->trans("HelpAbandonBadCustomer"), - 1); - print '</span>'; + print $form->textwithpicto($langs->trans("Abandoned").':', $langs->trans("HelpAbandonBadCustomer"), - 1); print '</td><td class="right">'.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye, 'MT')).'</td><td> </td></tr>'; // $resteapayeraffiche=0; $cssforamountpaymentcomplete = 'amountpaymentneutral'; @@ -4871,9 +4947,7 @@ // Paye partiellement ou Abandon 'product_returned' if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'product_returned') { print '<tr><td colspan="'.$nbcols.'" class="nowrap right">'; - print '<span class="opacitymedium">'; - print $form->textwithpicto($langs->trans("ProductReturned"), $langs->trans("HelpAbandonProductReturned"), - 1); - print '</span>'; + print $form->textwithpicto($langs->trans("ProductReturned").':', $langs->trans("HelpAbandonProductReturned"), - 1); print '</td><td class="right">'.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye, 'MT')).'</td><td> </td></tr>'; $resteapayeraffiche = 0; $cssforamountpaymentcomplete = 'amountpaymentneutral'; @@ -4884,52 +4958,48 @@ $text = $langs->trans("HelpAbandonOther"); if ($object->close_note) $text .= '<br><br><b>'.$langs->trans("Reason").'</b>:'.$object->close_note; - print '<span class="opacitymedium">'; - print $form->textwithpicto($langs->trans("Abandoned"), $text, - 1); - print '</span>'; + print $form->textwithpicto($langs->trans("Abandoned").':', $text, - 1); print '</td><td class="right">'.price(price2num($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye, 'MT')).'</td><td> </td></tr>'; $resteapayeraffiche = 0; $cssforamountpaymentcomplete = 'amountpaymentneutral'; } // Billed - print '<tr><td colspan="'.$nbcols.'" class="right">'; - print '<span class="opacitymedium">'; - print $langs->trans("Billed"); - print '</td><td class="right">'.price($object->total_ttc).'</td><td> </td></tr>'; + print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("Billed").' :</td><td class="right">'.price($object->total_ttc).'</td><td> </td></tr>'; // Remainder to pay print '<tr><td colspan="'.$nbcols.'" class="right">'; - print '<span class="opacitymedium">'; print $langs->trans('RemainderToPay'); if ($resteapayeraffiche < 0) - print ' ('.$langs->trans('ExcessReceived').')'; - print '</span>'; - print '</td>'; + print ' ('.$langs->trans('ExcessReceived').')'; + print ' :</td>'; print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayeraffiche).'</td>'; print '<td class="nowrap"> </td></tr>'; // Retained warranty : usualy use on construction industry if (!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty) { - // Billed - retained warranty - if ($object->type == Facture::TYPE_SITUATION) - { - $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100; - } else { - // Because one day retained warranty could be used on standard invoices - $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; - } - - $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty; - - print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')).' :</td><td align="right">'.price($billedWithRetainedWarranty).'</td><td> </td></tr>'; - - // retained warranty - print '<tr><td colspan="'.$nbcols.'" align="right">'; - print $langs->trans("RetainedWarranty").' ('.$object->retained_warranty.'%)'; - print !empty($object->retained_warranty_date_limit) ? ' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : ''; - print ' :</td><td align="right">'.price($retainedWarranty).'</td><td> </td></tr>'; - } - } else // Credit note + // Billed - retained warranty + if ($object->type == Facture::TYPE_SITUATION) + { + $retainedWarranty = $total_global_ttc * $object->retained_warranty / 100; + } + else + { + // Because one day retained warranty could be used on standard invoices + $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; + } + + $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty; + + print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')).' :</td><td align="right">'.price($billedWithRetainedWarranty).'</td><td> </td></tr>'; + + // retained warranty + print '<tr><td colspan="'.$nbcols.'" align="right">'; + print $langs->trans("RetainedWarranty").' ('.$object->retained_warranty.'%)'; + print !empty($object->retained_warranty_date_limit) ? ' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : ''; + print ' :</td><td align="right">'.price($retainedWarranty).'</td><td> </td></tr>'; + } + } + else // Credit note { $cssforamountpaymentcomplete = 'amountpaymentneutral'; @@ -4990,7 +5060,7 @@ { if ($object->situation_cycle_ref && $object->statut == 0) { - print '<!-- Area to change globally the situation percent -->'."\n"; + print '<!-- Area to change globally the situation percent -->'."\n"; print '<div class="div-table-responsive">'; print '<form name="updatealllines" id="updatealllines" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'#updatealllines" method="POST">'; @@ -5014,7 +5084,7 @@ print '<tr class="nodrag nodrop">'; // Adds a line numbering column if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - print '<td align="center" width="5"> </td>'; + print '<td align="center" width="5"> </td>'; } print '<td> </td>'; print '<td class="nowrap right"><input type="text" size="1" value="" name="all_progress">%</td>'; @@ -5051,7 +5121,7 @@ // Form to add new line if ($object->statut == 0 && $usercancreate && $action != 'valid' && $action != 'editline') { - if ($action != 'editline' && $action != 'selectlines') + if ($action != 'editline' && $action != 'selectlines') { // Add free products/services $object->formAddObjectLine(1, $mysoc, $soc); @@ -5066,7 +5136,7 @@ print "</form>\n"; - print dol_get_fiche_end(); + dol_fiche_end(); // Actions buttons @@ -5102,7 +5172,9 @@ print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('Modify').'</span>'; } } - } else { + } + else + { print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseDispatchedInBookkeeping").'">'.$langs->trans('Modify').'</span>'; } } @@ -5117,7 +5189,7 @@ && ($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED || ($object->statut == 1 && $object->paye == 1)) // Condition ($object->statut == 1 && $object->paye == 1) should not happened but can be found due to corrupted data && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) // A paid invoice (partially or completely) { - if ($object->close_code != 'replaced' || (!$objectidnext)) // Not replaced by another invoice or replaced but the replacement invoice has been deleted + if ($object->close_code != 'replaced' || (!$objectidnext)) // Not replaced by another invoice or replaced but the replacement invoice has been deleted { print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=reopen">'.$langs->trans('ReOpen').'</a>'; } else { @@ -5141,7 +5213,8 @@ } else { if ($usercansend) { print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'; - } else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a>'; + } else + print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a>'; } } } @@ -5159,10 +5232,14 @@ } else { print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('MakeWithdrawRequest').'</span>'; } - } else { + } + else + { //print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("MakeWithdrawRequest").'</a>'; } - } else { + } + else + { //print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$langs->trans("MakeWithdrawRequest").'</a>'; } } @@ -5170,9 +5247,9 @@ // POS Ticket if (!empty($conf->takepos->enabled) && $object->module_source == 'takepos') { - $langs->load("cashdesk"); - $receipt_url = DOL_URL_ROOT."/takepos/receipt.php"; - print '<a target="_blank" class="butAction" href="'.$receipt_url.'?facid='.$object->id.'">'.$langs->trans('POSTicket').'</a>'; + $langs->load("cashdesk"); + $receipt_url = DOL_URL_ROOT."/takepos/receipt.php"; + print '<a target="_blank" class="butAction" href="'.$receipt_url.'?facid='.$object->id.'">'.$langs->trans('POSTicket').'</a>'; } // Create payment @@ -5196,7 +5273,9 @@ if ($resteapayer == 0) { print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseRemainderToPayIsZero").'">'.$langs->trans('DoPaymentBack').'</span>'; - } else { + } + else + { print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement.php?facid='.$object->id.'&action=create&accountid='.$object->fk_account.'">'.$langs->trans('DoPaymentBack').'</a>'; } } @@ -5235,13 +5314,17 @@ { // If one payment or one credit note was linked to this invoice print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=paid">'.$langs->trans('ClassifyPaidPartially').'</a>'; - } else { + } + else + { if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) { if ($objectidnext) { print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('ClassifyCanceled').'</span>'; - } else { + } + else + { print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=canceled">'.$langs->trans('ClassifyCanceled').'</a>'; } } @@ -5253,26 +5336,26 @@ { if (!$objectidnext) { - print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&fac_avoir='.$object->id.'&action=create&type=2'.($object->fk_project > 0 ? '&projectid='.$object->fk_project : '').($object->entity > 0 ? '&originentity='.$object->entity : '').'">'.$langs->trans("CreateCreditNote").'</a>'; + print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&fac_avoir='.$object->id.'&action=create&type=2'.($object->fk_project > 0 ? '&projectid='.$object->fk_project : '').''.($object->entity > 0 ? '&originentity='.$object->entity : '').'">'.$langs->trans("CreateCreditNote").'</a>'; } } // For situation invoice with excess received if ($object->statut > Facture::STATUS_DRAFT && $object->type == Facture::TYPE_SITUATION - && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) > 0 - && $usercancreate - && !$objectidnext - && $object->is_last_in_cycle() - && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE - ) + && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) > 0 + && $usercancreate + && !$objectidnext + && $object->is_last_in_cycle() + && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE + ) { if ($usercanunvalidate) - { - print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&fac_avoir='.$object->id.'&invoiceAvoirWithLines=1&action=create&type=2'.($object->fk_project > 0 ? '&projectid='.$object->fk_project : '').'">'.$langs->trans("CreateCreditNote").'</a>'; - } else { - print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateCreditNote").'</span>'; - } + { + print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&fac_avoir='.$object->id.'&invoiceAvoirWithLines=1&action=create&type=2'.($object->fk_project > 0 ? '&projectid='.$object->fk_project : '').'">'.$langs->trans("CreateCreditNote").'</a>'; + } else { + print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateCreditNote").'</span>'; + } } // Clone @@ -5291,21 +5374,23 @@ } // Remove situation from cycle - if (in_array($object->statut, array(Facture::STATUS_CLOSED, Facture::STATUS_VALIDATED)) + if ($object->statut > Facture::STATUS_DRAFT && $object->type == Facture::TYPE_SITUATION && $usercancreate && !$objectidnext && $object->situation_counter > 1 && $object->is_last_in_cycle() && $usercanunvalidate - ) + ) { - if (($object->total_ttc - $totalcreditnotes) == 0) - { - print '<a id="butSituationOut" class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=situationout">'.$langs->trans("RemoveSituationFromCycle").'</a>'; - } else { - print '<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseNotEnouthCreditNote").'" >'.$langs->trans("RemoveSituationFromCycle").'</a>'; - } + if (($object->total_ttc - $totalcreditnotes) == 0) + { + print '<a id="butSituationOut" class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&action=situationout">'.$langs->trans("RemoveSituationFromCycle").'</a>'; + } + else + { + print '<a id="butSituationOutRefused" class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseNotEnouthCreditNote").'" >'.$langs->trans("RemoveSituationFromCycle").'</a>'; + } } // Create next situation invoice @@ -5326,20 +5411,27 @@ //var_dump($isErasable); if ($isErasable == -4) { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecausePayments").'">'.$langs->trans('Delete').'</a>'; - } elseif ($isErasable == -3) { + } + elseif ($isErasable == -3) { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseNotLastSituationInvoice").'">'.$langs->trans('Delete').'</a>'; - } elseif ($isErasable == -2) { + } + elseif ($isErasable == -2) { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseNotLastInvoice").'">'.$langs->trans('Delete').'</a>'; - } elseif ($isErasable == -1) { + } + elseif ($isErasable == -1) { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseDispatchedInBookkeeping").'">'.$langs->trans('Delete').'</a>'; - } elseif ($isErasable <= 0) // Any other cases + } + elseif ($isErasable <= 0) // Any other cases { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseNotErasable").'">'.$langs->trans('Delete').'</a>'; - } elseif ($objectidnext) + } + elseif ($objectidnext) { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('Delete').'</a>'; - } else { - print '<a class="butActionDelete'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'; + } + else + { + print '<a class="butActionDelete'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=delete">'.$langs->trans('Delete').'</a>'; } } else { print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans('Delete').'</a>'; @@ -5366,7 +5458,7 @@ print $formfile->showdocuments( 'facture', $filename, $filedir, $urlsource, $genallowed, - $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', + $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object, 0, 'remove_file_comfirm'); $somethingshown = $formfile->numoffiles; @@ -5376,10 +5468,10 @@ $compatibleImportElementsList = false; if ($usercancreate - && $object->statut == Facture::STATUS_DRAFT - && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION)) - { - $compatibleImportElementsList = array('commande', 'propal'); // import from linked elements + && $object->statut == Facture::STATUS_DRAFT + && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION)) + { + $compatibleImportElementsList = array('commande', 'propal'); // import from linked elements } $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList); --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_contact.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_contact.php @@ -42,7 +42,7 @@ $ref = GETPOST('ref', 'alpha'); $lineid = GETPOST('lineid', 'int'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); // Security check if ($user->socid) $socid = $user->socid; @@ -59,36 +59,45 @@ { $result = $object->fetch($id); - if ($result > 0 && $id > 0) - { - $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } + if ($result > 0 && $id > 0) + { + $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); + } if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; - } else { + } + else + { if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } -} // Toggle the status of a contact +} + +// Toggle the status of a contact elseif ($action == 'swapstatut' && $user->rights->facture->creer) { if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne')); - } else { + $result = $object->swapContactStatus(GETPOST('ligne')); + } + else + { dol_print_error($db); } -} // Deletes a contact +} + +// Deletes a contact elseif ($action == 'deletecontact' && $user->rights->facture->creer) { $object->fetch($id); @@ -98,7 +107,8 @@ { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; - } else { + } + else { dol_print_error($db); } } @@ -134,7 +144,7 @@ $totalpaye = $object->getSommePaiement(); - print dol_get_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), -1, 'bill'); + dol_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), -1, 'bill'); // Invoice content @@ -149,36 +159,36 @@ // Project if (!empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref .= '<br>'.$langs->trans('Project').' '; - if ($user->rights->facture->creer) - { - if ($action != 'classify') { - //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; + $langs->load("projects"); + $morehtmlref .= '<br>'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') { + //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; $morehtmlref .= ' : '; - } - 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="'.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 .= ''; - } - } + } + 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="'.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>'; @@ -186,7 +196,7 @@ dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); - print dol_get_fiche_end(); + dol_fiche_end(); print '<br>'; @@ -194,10 +204,12 @@ $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); foreach ($dirtpls as $reldir) { - $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); - if ($res) break; - } - } else { + $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); + if ($res) break; + } + } + else + { // Record not found print "ErrorRecordNotFound"; } --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_document.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_document.php @@ -45,7 +45,7 @@ $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); // Security check @@ -101,9 +101,9 @@ $upload_dir = $conf->facture->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); $head = facture_prepare_head($object); - print dol_get_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill'); + dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill'); - $totalpaye = $object->getSommePaiement(); + $totalpaye = $object->getSommePaiement(); // Build file list $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); @@ -114,54 +114,54 @@ } - // Invoice content + // Invoice content - $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; + $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; - $morehtmlref = '<div class="refidno">'; - // Ref customer - $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); - // Project - if (!empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref .= '<br>'.$langs->trans('Project').' '; - if ($user->rights->facture->creer) - { - if ($action != 'classify') - //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; - $morehtmlref .= ' : '; - 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="'.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>'; + $morehtmlref = '<div class="refidno">'; + // Ref customer + $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); + // Project + if (!empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref .= '<br>'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; + $morehtmlref .= ' : '; + 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="'.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>'; - $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0); print '<div class="fichecenter">'; print '<div class="underbanner clearboth"></div>'; @@ -174,17 +174,21 @@ print "</div>\n"; - print dol_get_fiche_end(); + dol_fiche_end(); $modulepart = 'facture'; $permission = $user->rights->facture->creer; $permtoedit = $user->rights->facture->creer; $param = '&id='.$object->id; include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; - } else { + } + else + { dol_print_error($db); } -} else { +} +else +{ print $langs->trans("ErrorUnknown"); } --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_info.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_info.php @@ -56,7 +56,7 @@ $object->info($object->id); $head = facture_prepare_head($object); -print dol_get_fiche_head($head, 'info', $langs->trans("InvoiceCustomer"), -1, 'bill'); +dol_fiche_head($head, 'info', $langs->trans("InvoiceCustomer"), -1, 'bill'); $totalpaye = $object->getSommePaiement(); @@ -120,7 +120,7 @@ print '</div>'; -print dol_get_fiche_end(); +dol_fiche_end(); // End of page llxFooter(); --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_invoicetemplate_list.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_invoicetemplate_list.php @@ -53,8 +53,6 @@ $socid = GETPOST('socid', 'int'); -$socid = GETPOST('socid', 'int'); - // Security check $id = (GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int')); $lineid = GETPOST('lineid', 'int'); @@ -108,7 +106,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label('facture_rec'); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); @@ -135,8 +133,14 @@ 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), ); // Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); @@ -147,11 +151,6 @@ } -if ($socid > 0) { - $tmpthirdparty = new Societe($db); - $res = $tmpthirdparty->fetch($socid); - if ($res > 0) $search_societe = $tmpthirdparty->name; -} /* * Actions @@ -268,7 +267,7 @@ if ($search_status == -1) $sql .= ' AND suspended = 1'; } $sql .= dolSqlDateFilter('f.date_last_gen', $search_day, $search_month, $search_year); -$sql .= dolSqlDateFilter('f.date_when', $search_day_date_when, $search_month_date_when, $search_year_date_when); +$sql .= dolSqlDateFilter('f.date_last_gen', $search_day_date_when, $search_month_date_when, $search_year_date_when); $sql .= $db->order($sortfield, $sortorder); @@ -351,7 +350,7 @@ if (!empty($arrayfields['f.titre']['checked'])) { print '<td class="liste_titre left">'; - print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">'; + print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">'; print '</td>'; } // Thirpdarty @@ -472,7 +471,7 @@ } // Action column print '<td class="liste_titre" align="middle">'; - $searchpicto = $form->showFilterButtons(); + $searchpicto = $form->showFilterAndCheckAddButtons(0, 'checkforselect', 1); print $searchpicto; print '</td>'; print "</tr>\n"; @@ -496,7 +495,7 @@ // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; if (!empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'], $_SERVER['PHP_SELF'], "f.suspended,f.frequency", "", $param, 'align="center"', $sortfield, $sortorder); - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'center maxwidthsearch '); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'nomaxwidthsearch '); print "</tr>\n"; if ($num > 0) @@ -523,68 +522,68 @@ if (!empty($arrayfields['f.titre']['checked'])) { - print '<td class="nowrap tdoverflowmax200">'; - print $invoicerectmp->getNomUrl(1); - print "</a>"; - print "</td>\n"; - if (!$i) $totalarray['nbfield']++; + print '<td>'; + print $invoicerectmp->getNomUrl(1); + print "</a>"; + print "</td>\n"; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['s.nom']['checked'])) { - print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1, 'customer').'</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1, 'customer').'</td>'; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['f.total']['checked'])) { - print '<td class="nowrap right">'.price($objp->total).'</td>'."\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total'; - $totalarray['val']['f.total'] += $objp->total; + print '<td class="nowrap right">'.price($objp->total).'</td>'."\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total'; + $totalarray['val']['f.total'] += $objp->total; } if (!empty($arrayfields['f.tva']['checked'])) { - print '<td class="nowrap right">'.price($objp->total_vat).'</td>'."\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.tva'; - $totalarray['val']['f.tva'] += $objp->total_vat; + print '<td class="nowrap right">'.price($objp->total_vat).'</td>'."\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.tva'; + $totalarray['val']['f.tva'] += $objp->total_vat; } if (!empty($arrayfields['f.total_ttc']['checked'])) { - print '<td class="nowrap right">'.price($objp->total_ttc).'</td>'."\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc'; - $totalarray['val']['f.total_ttc'] += $objp->total_ttc; + print '<td class="nowrap right">'.price($objp->total_ttc).'</td>'."\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc'; + $totalarray['val']['f.total_ttc'] += $objp->total_ttc; } // Payment term if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) { - print '<td class="right">'; - $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none'); - print '</td>'."\n"; - if (!$i) $totalarray['nbfield']++; + print '<td class="right">'; + $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none'); + print '</td>'."\n"; + if (!$i) $totalarray['nbfield']++; } // Payment mode if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) { - print '<td class="right">'; - $form->form_modes_reglement('', $objp->fk_mode_reglement, 'none'); - print '</td>'."\n"; - if (!$i) $totalarray['nbfield']++; + print '<td class="right">'; + $form->form_modes_reglement('', $objp->fk_mode_reglement, 'none'); + print '</td>'."\n"; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['recurring']['checked'])) { - print '<td class="center">'.yn($objp->frequency ? 1 : 0).'</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'.yn($objp->frequency ? 1 : 0).'</td>'; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['f.frequency']['checked'])) { - print '<td class="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>'; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['f.unit_frequency']['checked'])) { - print '<td class="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>'; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['f.nb_gen_done']['checked'])) { @@ -596,10 +595,10 @@ // Date last generation if (!empty($arrayfields['f.date_last_gen']['checked'])) { - print '<td class="center">'; - print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen), 'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>'); - print '</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'; + print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen), 'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>'); + print '</td>'; + if (!$i) $totalarray['nbfield']++; } // Date next generation if (!empty($arrayfields['f.date_when']['checked'])) @@ -610,7 +609,9 @@ if (!$invoicerectmp->isMaxNbGenReached()) { if (!$objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) print img_warning($langs->trans("Late")); - } else { + } + else + { print img_info($langs->trans("MaxNumberOfGenerationReached")); } print '</div>'; @@ -619,17 +620,17 @@ } if (!empty($arrayfields['f.datec']['checked'])) { - print '<td class="center">'; - print dol_print_date($db->jdate($objp->datec), 'dayhour'); - print '</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'; + print dol_print_date($db->jdate($objp->datec), 'dayhour'); + print '</td>'; + if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['f.tms']['checked'])) { - print '<td class="center">'; - print dol_print_date($db->jdate($objp->tms), 'dayhour'); - print '</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'; + print dol_print_date($db->jdate($objp->tms), 'dayhour'); + print '</td>'; + if (!$i) $totalarray['nbfield']++; } $obj = $objp; @@ -641,10 +642,10 @@ print $hookmanager->resPrint; // Status if (!empty($arrayfields['status']['checked'])) { - print '<td class="center">'; - print $invoicerectmp->getLibStatut(3, 0); - print '</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="center">'; + print $invoicerectmp->getLibStatut(3, 0); + print '</td>'; + if (!$i) $totalarray['nbfield']++; } // Action column print '<td class="center">'; @@ -653,14 +654,19 @@ if ($invoicerectmp->isMaxNbGenReached()) { print $langs->trans("MaxNumberOfGenerationReached"); - } elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) + } + elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) { print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$objp->socid.'&fac_rec='.$objp->facid.'">'; print $langs->trans("CreateBill").'</a>'; - } else { + } + else + { print $form->textwithpicto('', $langs->trans("DateIsNotEnough")); } - } else { + } + else + { print " "; } if (!$i) $totalarray['nbfield']++; @@ -670,7 +676,9 @@ $i++; } - } else { + } + else + { $colspan = 1; foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; @@ -685,7 +693,9 @@ print "</form>"; $db->free($resql); -} else { +} +else +{ dol_print_error($db); } --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_list.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_list.php @@ -5,7 +5,7 @@ * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> - * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es> + * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> @@ -39,9 +39,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; -if (!empty($conf->margin->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; -} require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; @@ -64,7 +61,7 @@ $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $massaction = GETPOST('massaction', 'alpha'); $show_files = GETPOST('show_files', 'int'); $confirm = GETPOST('confirm', 'alpha'); @@ -73,7 +70,7 @@ if ($contextpage == 'poslist') { - $_GET['optioncss'] = 'print'; + $_GET['optioncss'] = 'print'; } $lineid = GETPOST('lineid', 'int'); @@ -103,7 +100,7 @@ $search_pos_source = GETPOST('search_pos_source', 'alpha'); $search_town = GETPOST('search_town', 'alpha'); $search_zip = GETPOST('search_zip', 'alpha'); -$search_state = GETPOST("search_state"); +$search_state = trim(GETPOST("search_state")); $search_country = GETPOST("search_country", 'int'); $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int'); $search_user = GETPOST('search_user', 'int'); @@ -114,7 +111,7 @@ $search_date_valid_end = dol_mktime(23, 59, 59, GETPOST('search_date_valid_endmonth', 'int'), GETPOST('search_date_valid_endday', 'int'), GETPOST('search_date_valid_endyear', 'int')); $search_datelimit_start = dol_mktime(0, 0, 0, GETPOST('search_datelimit_startmonth', 'int'), GETPOST('search_datelimit_startday', 'int'), GETPOST('search_datelimit_startyear', 'int')); $search_datelimit_end = dol_mktime(23, 59, 59, GETPOST('search_datelimit_endmonth', 'int'), GETPOST('search_datelimit_endday', 'int'), GETPOST('search_datelimit_endyear', 'int')); -$search_categ_cus = GETPOST("search_categ_cus", 'int'); +$search_categ_cus = trim(GETPOST("search_categ_cus", 'int')); $search_btn = GETPOST('button_search', 'alpha'); $search_remove_btn = GETPOST('button_removefilter', 'alpha'); @@ -128,7 +125,7 @@ $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters +if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; if (!$sortorder && !empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == '1') $sortorder = $conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER; if (!$sortorder) $sortorder = 'DESC'; @@ -153,7 +150,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label('facture'); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); @@ -206,14 +203,8 @@ 'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>200), 'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>210), 'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>220), // Not enabled by default because slow - 'total_pa' => array('label' => ($conf->global->MARGIN_TYPE == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)), - 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)), - 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)), - 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)), 'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500), 'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), - 'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))), - 'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))), 'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), ); @@ -223,8 +214,14 @@ } // Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); @@ -300,20 +297,25 @@ include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($massaction == 'makepayment') { - $arrayofselected = is_array($toselect) ? $toselect : array(); +if ($massaction == 'makepayment'){ + $arrayofselected=is_array($toselect)?$toselect:array(); $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected); header('Location: '.$loc); exit; -} elseif ($massaction == 'withdrawrequest') { +} +elseif ($massaction == 'withdrawrequest') +{ $langs->load("withdrawals"); - if (!$user->rights->prelevement->bons->creer) { + if (!$user->rights->prelevement->bons->creer) + { $error++; setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); - } else { + } + else + { //Checking error $error = 0; @@ -323,7 +325,8 @@ { $objecttmp = new Facture($db); $result = $objecttmp->fetch($toselectid); - if ($result > 0) { + if ($result > 0) + { $totalpaye = $objecttmp->getSommePaiement(); $totalcreditnotes = $objecttmp->getSumCreditNotesUsed(); $totaldeposits = $objecttmp->getSumDepositsUsed(); @@ -360,10 +363,12 @@ if ($numprlv > 0) { $error++; setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings'); - } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'PRE') { + } + elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'PRE') { $error++; setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors'); - } else { + } + else { $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done } } @@ -381,7 +386,9 @@ { $db->commit(); $nbwithdrawrequestok++; - } else { + } + else + { $db->rollback(); setEventMessages($aBill->error, $aBill->errors, 'errors'); } @@ -403,17 +410,13 @@ $form = new Form($db); $formother = new FormOther($db); $formfile = new FormFile($db); -$formmargin = null; -if (!empty($conf->margin->enabled)) { - $formmargin = new FormMargin($db); -} $bankaccountstatic = new Account($db); $facturestatic = new Facture($db); $formcompany = new FormCompany($db); $thirdpartystatic = new Societe($db); $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; $sql .= ' f.rowid as id, f.ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; $sql .= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,'; $sql .= ' f.fk_user_author,'; @@ -482,15 +485,15 @@ } if ($search_ref) $sql .= natural_search('f.ref', $search_ref); if ($search_refcustomer) $sql .= natural_search('f.ref_client', $search_refcustomer); -if ($search_type != '' && $search_type != '-1') $sql .= " AND f.type IN (".$db->sanitize($db->escape($search_type)).")"; +if ($search_type != '' && $search_type != '-1') $sql .= " AND f.type IN (".$db->escape($search_type).")"; if ($search_project_ref) $sql .= natural_search('p.ref', $search_project_ref); if ($search_project) $sql .= natural_search('p.title', $search_project); if ($search_societe) $sql .= natural_search('s.nom', $search_societe); if ($search_town) $sql .= natural_search('s.town', $search_town); if ($search_zip) $sql .= natural_search("s.zip", $search_zip); if ($search_state) $sql .= natural_search("state.nom", $search_state); -if ($search_country) $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')'; -if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')'; +if ($search_country) $sql .= " AND s.fk_pays IN (".$db->escape($search_country).')'; +if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$db->escape($search_type_thirdparty).')'; if ($search_company) $sql .= natural_search('s.nom', $search_company); if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1); if ($search_montant_vat != '') $sql .= natural_search('f.tva', $search_montant_vat, 1); @@ -513,8 +516,10 @@ if ($search_status == '1') $sql .= " AND f.fk_statut = 1"; // unpayed if ($search_status == '2') $sql .= " AND f.fk_statut = 2"; // payed Not that some corrupted data may contains f.fk_statut = 1 AND f.paye = 1 (it means payed too but should not happend. If yes, reopen and reclassify billed) if ($search_status == '3') $sql .= " AND f.fk_statut = 3"; // abandonned - } else { - $sql .= " AND f.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; // When search_status is '1,2' for example + } + else + { + $sql .= " AND f.fk_statut IN (".$db->escape($search_status).")"; // When search_status is '1,2' for example } } @@ -549,8 +554,6 @@ $sql .= ' f.paye, f.fk_statut, f.close_code,'; $sql .= ' f.datec, f.tms, f.date_closing,'; $sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,'; - $sql .= ' f.fk_user_author, f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva,'; - $sql .= ' f.multicurrency_total_tva, f.multicurrency_total_ttc,'; $sql .= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,'; $sql .= ' typent.code,'; $sql .= ' state.code_departement, state.nom,'; @@ -562,7 +565,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : ''); } -} else { +} +else +{ $sql .= natural_search(array_keys($fieldstosearchall), $sall); } @@ -664,26 +669,25 @@ 'presend'=>$langs->trans("SendByMail"), //'makepayment'=>$langs->trans("InvoicePaymentsLimits"), TODO Blank page when using this ); - if ($conf->prelevement->enabled && !empty($user->rights->prelevement->bons->creer)) { - $langs->load("withdrawals"); - $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest"); + if ($conf->prelevement->enabled) { + $langs->load("withdrawals"); + $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest"); } if ($user->rights->facture->supprimer) { if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) { - $arrayofmassactions['predeletedraft'] = $langs->trans("Deletedraft"); - } elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { // mass deletion never possible on invoices on such situation - $arrayofmassactions['predelete'] = $langs->trans("Delete"); + $arrayofmassactions['predeletedraft'] = $langs->trans("Deletedraft"); } - } + elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { // mass deletion never possible on invoices on such situation + $arrayofmassactions['predelete'] = $langs->trans("Delete"); + } + } if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); - // Show the new button only when this page is not opend from the Extended POS - if ($contextpage != 'poslist') - { - $url = DOL_URL_ROOT.'/compta/facture/card.php?action=create'; - if (!empty($socid)) $url .= '&socid='.$socid; - $newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', $user->rights->facture->creer); + $newcardbutton = ''; + if ($user->rights->facture->creer && $contextpage != 'poslist') + { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/facture/card.php?action=create'); } $i = 0; @@ -731,7 +735,7 @@ $moreforfilter .= '</div>'; } // If the user can view prospects other than his' - if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) + if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire)) { include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '<div class="divsearchfield">'; @@ -740,7 +744,7 @@ $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); $moreforfilter .= '</div>'; } - if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) + if (!empty($conf->categorie->enabled)) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '<div class="divsearchfield">'; @@ -762,7 +766,6 @@ $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - // Show the massaction checkboxes only when this page is not opend from the Extended POS if ($massactionbutton && $contextpage != 'poslist') $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); print '<div class="div-table-responsive">'; @@ -811,10 +814,12 @@ { print '<td class="liste_titre center">'; print '<div class="nowrap">'; - print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); + print $langs->trans('From').' '; + print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1); print '</div>'; print '<div class="nowrap">'; - print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); + print $langs->trans('to').' '; + print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1); print '</div>'; print '</td>'; } @@ -823,10 +828,12 @@ { print '<td class="liste_titre center">'; print '<div class="nowrap">'; - print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); + print $langs->trans('From').' '; + print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1); print '</div>'; print '<div class="nowrap">'; - print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); + print $langs->trans('to').' '; + print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1); print '</div>'; print '</td>'; } @@ -835,14 +842,12 @@ { print '<td class="liste_titre center">'; print '<div class="nowrap">'; - /* print $langs->trans('From').' '; print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1); print '</div>'; print '<div class="nowrap">'; - print $langs->trans('to').' ';*/ - print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before")); - print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert"); + print $langs->trans('to').' '; + print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1); print '</div>'; print '</td>'; } @@ -854,7 +859,7 @@ // Project label if (!empty($arrayfields['p.title']['checked'])) { - print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.$search_project.'"></td>'; + print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.$search_project.'"></td>'; } // Thirdparty if (!empty($arrayfields['s.nom']['checked'])) @@ -958,8 +963,8 @@ } if (!empty($arrayfields['f.retained_warranty']['checked'])) { - print '<td class="liste_titre" align="right">'; - print '</td>'; + print '<td class="liste_titre" align="right">'; + print '</td>'; } if (!empty($arrayfields['dynamount_payed']['checked'])) { @@ -1019,26 +1024,6 @@ if (!empty($arrayfields['f.date_closing']['checked'])) { print '<td class="liste_titre">'; - print '</td>'; - } - if (!empty($arrayfields['total_pa']['checked'])) - { - print '<td class="liste_titre right">'; - print '</td>'; - } - if (!empty($arrayfields['total_margin']['checked'])) - { - print '<td class="liste_titre right">'; - print '</td>'; - } - if (!empty($arrayfields['total_margin_rate']['checked'])) - { - print '<td class="liste_titre right">'; - print '</td>'; - } - if (!empty($arrayfields['total_mark_rate']['checked'])) - { - print '<td class="liste_titre right">'; print '</td>'; } @@ -1061,24 +1046,12 @@ print '<td class="liste_titre">'; print '</td>'; } - if (!empty($arrayfields['f.note_public']['checked'])) - { - // Note public - print '<td class="liste_titre">'; - print '</td>'; - } - if (!empty($arrayfields['f.note_private']['checked'])) - { - // Note private - print '<td class="liste_titre">'; - print '</td>'; - } // Status if (!empty($arrayfields['f.fk_statut']['checked'])) { print '<td class="liste_titre maxwidthonsmartphone right">'; $liststatus = array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '1,2'=>$langs->trans("BillShortStatusNotPaid").'+'.$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled")); - print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1); + print $form->selectarray('search_status', $liststatus, $search_status, 1); print '</td>'; } // Action column @@ -1124,10 +1097,6 @@ if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); if (!empty($arrayfields['multicurrency_rtp']['checked'])) print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); - if (!empty($arrayfields['total_pa']['checked'])) print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); - if (!empty($arrayfields['total_margin']['checked'])) print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); - if (!empty($arrayfields['total_margin_rate']['checked'])) print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); - if (!empty($arrayfields['total_mark_rate']['checked'])) print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields @@ -1137,8 +1106,6 @@ if (!empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); if (!empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); if (!empty($arrayfields['f.date_closing']['checked'])) print_liste_field_titre($arrayfields['f.date_closing']['label'], $_SERVER["PHP_SELF"], "f.date_closing", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); - if (!empty($arrayfields['f.note_public']['checked'])) print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - if (!empty($arrayfields['f.note_private']['checked'])) print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap '); if (!empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut,f.paye,f.type,dynamount_payed", "", $param, 'class="right"', $sortfield, $sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); print "</tr>\n"; @@ -1161,9 +1128,9 @@ $facturestatic->ref = $obj->ref; $facturestatic->ref_client = $obj->ref_client; $facturestatic->type = $obj->type; - $facturestatic->total_ht = $obj->total_ht; - $facturestatic->total_tva = $obj->total_vat; - $facturestatic->total_ttc = $obj->total_ttc; + $facturestatic->total_ht = $obj->total_ht; + $facturestatic->total_tva = $obj->total_vat; + $facturestatic->total_ttc = $obj->total_ttc; $facturestatic->multicurrency_code = $obj->multicurrency_code; $facturestatic->multicurrency_tx = $obj->multicurrency_tx; $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht; @@ -1172,23 +1139,23 @@ $facturestatic->statut = $obj->fk_statut; $facturestatic->close_code = $obj->close_code; $facturestatic->total_ttc = $obj->total_ttc; - $facturestatic->paye = $obj->paye; - $facturestatic->fk_soc = $obj->fk_soc; - - $facturestatic->date = $db->jdate($obj->df); - $facturestatic->date_valid = $db->jdate($obj->date_valid); - $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite); - - $facturestatic->note_public = $obj->note_public; + $facturestatic->paye = $obj->paye; + $facturestatic->fk_soc = $obj->fk_soc; + + $facturestatic->date = $db->jdate($obj->df); + $facturestatic->date_valid = $db->jdate($obj->date_valid); + $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite); + + $facturestatic->note_public = $obj->note_public; $facturestatic->note_private = $obj->note_private; if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_RETAINED_WARRANTY) { - $facturestatic->retained_warranty = $obj->retained_warranty; - $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit; - $facturestatic->situation_final = $obj->retained_warranty_date_limit; - $facturestatic->situation_final = $obj->retained_warranty_date_limit; - $facturestatic->situation_cycle_ref = $obj->situation_cycle_ref; - $facturestatic->situation_counter = $obj->situation_counter; + $facturestatic->retained_warranty = $obj->retained_warranty; + $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit; + $facturestatic->situation_final = $obj->retained_warranty_date_limit; + $facturestatic->situation_final = $obj->retained_warranty_date_limit; + $facturestatic->situation_cycle_ref = $obj->situation_cycle_ref; + $facturestatic->situation_counter = $obj->situation_counter; } $thirdpartystatic->id = $obj->socid; $thirdpartystatic->name = $obj->name; @@ -1231,38 +1198,34 @@ $facturestatic->alreadypaid = $paiement; - $marginInfo = array(); - if (!empty($conf->margin->enabled)) { - $facturestatic->fetch_lines(); - $marginInfo = $formmargin->getMarginInfosArray($facturestatic); - } - - print '<tr class="oddeven"'; - if ($contextpage == 'poslist') - { - print ' onclick="parent.$(\'#poslines\').load(\'invoice.php?action=history&placeid='.$obj->id.'\', function() {parent.$.colorbox.close();});"'; - } - print '>'; - - // No - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) { - print '<td>'.(($offset * $limit) + $i).'</td>'; - } - - // Ref + print '<tr class="oddeven"'; + if ($contextpage == 'poslist') + { + print ' onclick="parent.$(\'#poslines\').load(\'invoice.php?action=history&placeid='.$obj->id.'\', function() {parent.$.colorbox.close();});"'; + } + print '>'; + + // No + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) { + print '<td>'.(($offset * $limit) + $i).'</td>'; + } + + // Ref if (!empty($arrayfields['f.ref']['checked'])) { - print '<td class="nowraponall">'; + print '<td class="nowrap">'; print '<table class="nobordernopadding"><tr class="nocellnopadd">'; print '<td class="nobordernopadding nowraponall">'; - if ($contextpage == 'poslist') - { - print $obj->ref; - } else { - print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1); - } + if ($contextpage == 'poslist') + { + print $obj->ref; + } + else + { + print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1); + } $filename = dol_sanitizeFileName($obj->ref); $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref); @@ -1288,7 +1251,7 @@ // Type if (!empty($arrayfields['f.type']['checked'])) { - print '<td class="nowraponall tdoverflowmax100" title="'.$facturestatic->getLibType().'">'; + print '<td class="nowrap">'; print $facturestatic->getLibType(); print "</td>"; if (!$i) $totalarray['nbfield']++; @@ -1297,7 +1260,7 @@ // Date if (!empty($arrayfields['f.date']['checked'])) { - print '<td align="center" class="nowraponall">'; + print '<td align="center" class="nowrap">'; print dol_print_date($db->jdate($obj->df), 'day'); print '</td>'; if (!$i) $totalarray['nbfield']++; @@ -1306,7 +1269,7 @@ // Date if (!empty($arrayfields['f.date_valid']['checked'])) { - print '<td align="center" class="nowraponall">'; + print '<td align="center" class="nowrap">'; print dol_print_date($db->jdate($obj->date_valid), 'day'); print '</td>'; if (!$i) $totalarray['nbfield']++; @@ -1315,10 +1278,10 @@ // Date limit if (!empty($arrayfields['f.date_lim_reglement']['checked'])) { - print '<td align="center" class="nowraponall">'.dol_print_date($datelimit, 'day'); + print '<td align="center" class="nowrap">'.dol_print_date($datelimit, 'day'); if ($facturestatic->hasDelay()) { - print img_warning($langs->trans('Alert').' - '.$langs->trans('Late')); + print img_warning($langs->trans('Alert').' - '.$langs->trans('Late')); } print '</td>'; if (!$i) $totalarray['nbfield']++; @@ -1327,7 +1290,7 @@ // Project ref if (!empty($arrayfields['p.ref']['checked'])) { - print '<td class="nocellnopadd nowraponall">'; + print '<td class="nocellnopadd nowrap">'; if ($obj->project_id > 0) { print $projectstatic->getNomUrl(1); @@ -1339,24 +1302,26 @@ // Project title if (!empty($arrayfields['p.title']['checked'])) { - print '<td class="nowraponall">'; - if ($obj->project_id > 0) - { - print $projectstatic->title; - } - print '</td>'; - if (!$i) $totalarray['nbfield']++; + print '<td class="nowrap">'; + if ($obj->project_id > 0) + { + print $projectstatic->title; + } + print '</td>'; + if (!$i) $totalarray['nbfield']++; } // Third party if (!empty($arrayfields['s.nom']['checked'])) { print '<td class="tdoverflowmax200">'; - if ($contextpage == 'poslist') + if ($contextpage == 'poslist') { - print $thirdpartystatic->name; - } else { - print $thirdpartystatic->getNomUrl(1, 'customer'); + print $thirdpartystatic->name; + } + else + { + print $thirdpartystatic->getNomUrl(1, 'customer'); } print '</td>'; if (!$i) $totalarray['nbfield']++; @@ -1372,7 +1337,7 @@ // Zip if (!empty($arrayfields['s.zip']['checked'])) { - print '<td class="nowraponall">'; + print '<td>'; print $obj->zip; print '</td>'; if (!$i) $totalarray['nbfield']++; @@ -1414,7 +1379,7 @@ // Payment mode if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) { - print '<td class="tdoverflowmax100">'; + print '<td>'; $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1); print '</td>'; if (!$i) $totalarray['nbfield']++; @@ -1450,7 +1415,7 @@ // Amount HT if (!empty($arrayfields['f.total_ht']['checked'])) { - print '<td class="right nowraponall">'.price($obj->total_ht)."</td>\n"; + print '<td class="right nowrap">'.price($obj->total_ht)."</td>\n"; if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht'; $totalarray['val']['f.total_ht'] += $obj->total_ht; @@ -1458,7 +1423,7 @@ // Amount VAT if (!empty($arrayfields['f.total_vat']['checked'])) { - print '<td class="right nowraponall">'.price($obj->total_vat)."</td>\n"; + print '<td class="right nowrap">'.price($obj->total_vat)."</td>\n"; if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat'; $totalarray['val']['f.total_vat'] += $obj->total_vat; @@ -1466,7 +1431,7 @@ // Amount LocalTax1 if (!empty($arrayfields['f.total_localtax1']['checked'])) { - print '<td class="right nowraponall">'.price($obj->total_localtax1)."</td>\n"; + print '<td class="right nowrap">'.price($obj->total_localtax1)."</td>\n"; if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1'; $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1; @@ -1474,7 +1439,7 @@ // Amount LocalTax2 if (!empty($arrayfields['f.total_localtax2']['checked'])) { - print '<td class="right nowraponall">'.price($obj->total_localtax2)."</td>\n"; + print '<td class="right nowrap">'.price($obj->total_localtax2)."</td>\n"; if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2'; $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2; @@ -1482,7 +1447,7 @@ // Amount TTC if (!empty($arrayfields['f.total_ttc']['checked'])) { - print '<td class="right nowraponall">'.price($obj->total_ttc)."</td>\n"; + print '<td class="right nowrap">'.price($obj->total_ttc)."</td>\n"; if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc'; $totalarray['val']['f.total_ttc'] += $obj->total_ttc; @@ -1493,7 +1458,7 @@ { $userstatic->id = $obj->fk_user_author; $userstatic->login = $obj->login; - print '<td class="center tdoverflowmax100">'; + print '<td align="center">'; if ($userstatic->id) print $userstatic->getLoginUrl(1); else print ' '; print "</td>\n"; @@ -1502,12 +1467,12 @@ if (!empty($arrayfields['f.retained_warranty']['checked'])) { - print '<td align="right">'.(!empty($obj->retained_warranty) ?price($obj->retained_warranty).'%' : ' ').'</td>'; + print '<td align="right">'.(!empty($obj->retained_warranty) ?price($obj->retained_warranty).'%' : ' ').'</td>'; } if (!empty($arrayfields['dynamount_payed']['checked'])) { - print '<td class="right nowraponall">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : ' ').'</td>'; // TODO Use a denormalized field + print '<td class="right nowrap">'.(!empty($totalpay) ?price($totalpay, 0, $langs) : ' ').'</td>'; // TODO Use a denormalized field if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalam'; $totalarray['val']['totalam'] += $totalpay; @@ -1516,7 +1481,7 @@ // Pending amount if (!empty($arrayfields['rtp']['checked'])) { - print '<td class="right nowraponall">'; + print '<td class="right nowrap">'; print (!empty($remaintopay) ? price($remaintopay, 0, $langs) : ' '); print '</td>'; // TODO Use a denormalized field if (!$i) $totalarray['nbfield']++; @@ -1528,14 +1493,14 @@ // Currency if (!empty($arrayfields['f.multicurrency_code']['checked'])) { - print '<td class="nowraponall">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n"; + print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n"; if (!$i) $totalarray['nbfield']++; } // Currency rate if (!empty($arrayfields['f.multicurrency_tx']['checked'])) { - print '<td class="nowraponall">'; + print '<td class="nowrap">'; $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code); print "</td>\n"; if (!$i) $totalarray['nbfield']++; @@ -1543,58 +1508,33 @@ // Amount HT if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) { - print '<td class="right nowraponall">'.price($obj->multicurrency_total_ht)."</td>\n"; + print '<td class="right nowrap">'.price($obj->multicurrency_total_ht)."</td>\n"; if (!$i) $totalarray['nbfield']++; } // Amount VAT if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) { - print '<td class="right nowraponall">'.price($obj->multicurrency_total_vat)."</td>\n"; + print '<td class="right nowrap">'.price($obj->multicurrency_total_vat)."</td>\n"; if (!$i) $totalarray['nbfield']++; } // Amount TTC if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) { - print '<td class="right nowraponall">'.price($obj->multicurrency_total_ttc)."</td>\n"; + print '<td class="right nowrap">'.price($obj->multicurrency_total_ttc)."</td>\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) { - print '<td class="right nowraponall">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : ' ').'</td>'; // TODO Use a denormalized field + print '<td class="right nowrap">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : ' ').'</td>'; // TODO Use a denormalized field if (!$i) $totalarray['nbfield']++; } // Pending amount if (!empty($arrayfields['multicurrency_rtp']['checked'])) { - print '<td class="right nowraponall">'; + print '<td class="right nowrap">'; print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : ' '); print '</td>'; // TODO Use a denormalized field - if (!$i) $totalarray['nbfield']++; - } - - // Total buying or cost price - if (!empty($arrayfields['total_pa']['checked'])) - { - print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - // Total margin - if (!empty($arrayfields['total_margin']['checked'])) - { - print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - // Total margin rate - if (!empty($arrayfields['total_margin_rate']['checked'])) - { - print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>'; - if (!$i) $totalarray['nbfield']++; - } - // total mark rate - if (!empty($arrayfields['total_mark_rate']['checked'])) - { - print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>'; if (!$i) $totalarray['nbfield']++; } @@ -1628,22 +1568,6 @@ print '</td>'; if (!$i) $totalarray['nbfield']++; } - // Note public - if (!empty($arrayfields['f.note_public']['checked'])) - { - print '<td class="center">'; - print dol_escape_htmltag($obj->note_public); - print '</td>'; - if (!$i) $totalarray['nbfield']++; - } - // Note private - if (!empty($arrayfields['f.note_private']['checked'])) - { - print '<td class="center">'; - print dol_escape_htmltag($obj->note_private); - print '</td>'; - if (!$i) $totalarray['nbfield']++; - } // Status if (!empty($arrayfields['f.fk_statut']['checked'])) { @@ -1653,7 +1577,7 @@ if (!$i) $totalarray['nbfield']++; } - // Action column (Show the massaction button only when this page is not opend from the Extended POS) + // Action column print '<td class="nowrap" align="center">'; if (($massactionbutton || $massaction) && $contextpage != 'poslist') // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined { @@ -1684,23 +1608,22 @@ print "</form>\n"; - // Show the file area only when this page is not opend from the Extended POS - if ($contextpage != 'poslist') { - $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; - - // Show list of available documents - $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource .= str_replace('&', '&', $param); - - $filedir = $diroutputmassaction; - $genallowed = $user->rights->facture->lire; - $delallowed = $user->rights->facture->creer; - $title = ''; - - print $formfile->showdocuments('massfilesarea_invoices', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); - } -} else { + $hidegeneratedfilelistifempty = 1; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + + // Show list of available documents + $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource .= str_replace('&', '&', $param); + + $filedir = $diroutputmassaction; + $genallowed = $user->rights->facture->lire; + $delallowed = $user->rights->facture->creer; + $title = ''; + + print $formfile->showdocuments('massfilesarea_invoices', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); +} +else +{ dol_print_error($db); } --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_note.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_note.php @@ -39,7 +39,7 @@ $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); // Security check $socid = 0; @@ -77,69 +77,69 @@ $object->fetch_thirdparty(); - $head = facture_prepare_head($object); + $head = facture_prepare_head($object); - $totalpaye = $object->getSommePaiement(); + $totalpaye = $object->getSommePaiement(); - print dol_get_fiche_head($head, 'note', $langs->trans("InvoiceCustomer"), -1, 'bill'); + dol_fiche_head($head, 'note', $langs->trans("InvoiceCustomer"), -1, 'bill'); - // Invoice content + // Invoice content - $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; + $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; - $morehtmlref = '<div class="refidno">'; - // Ref customer - $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); - // Project - if (!empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref .= '<br>'.$langs->trans('Project').' '; - if ($user->rights->facture->creer) - { - if ($action != 'classify') - //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; - $morehtmlref .= ' : '; - 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="'.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>'; + $morehtmlref = '<div class="refidno">'; + // Ref customer + $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); + // Project + if (!empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref .= '<br>'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; + $morehtmlref .= ' : '; + 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="'.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>'; - $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0); print '<div class="fichecenter">'; print '<div class="underbanner clearboth"></div>'; $cssclass = "titlefield"; - include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; - print dol_get_fiche_end(); + dol_fiche_end(); } // End of page --- /tmp/dsg/dolibarr/htdocs/compta/facture/github_prelevement.php +++ /tmp/dsg/dolibarr/htdocs/compta/facture/client_prelevement.php @@ -38,17 +38,20 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +if (!$user->rights->facture->lire) accessforbidden(); + // Load translation files required by the page $langs->loadLangs(array('bills', 'banks', 'withdrawals', 'companies')); $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $type = GETPOST('type', 'aZ09'); $fieldid = (!empty($ref) ? 'ref' : 'rowid'); if ($user->socid) $socid = $user->socid; +$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid); if ($type == 'bank-transfer') { $object = new FactureFournisseur($db); @@ -60,7 +63,6 @@ if ($id > 0 || !empty($ref)) { $ret = $object->fetch($id, $ref); - $isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0); if ($ret > 0) { $object->fetch_thirdparty(); @@ -69,13 +71,6 @@ $hookmanager->initHooks(array('directdebitcard', 'globalcard')); -if ($type == 'bank-transfer') { - $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', $fieldid, $isdraft); - if (!$user->rights->fournisseur->facture->lire) accessforbidden(); -} else { - $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft); - if (!$user->rights->facture->lire) accessforbidden(); -} /* @@ -88,45 +83,47 @@ if (empty($reshook)) { - if ($action == "new") - { - if ($object->id > 0) - { - $db->begin(); - - $newtype = $type; - $sourcetype = 'facture'; - if ($type == 'bank-transfer') { - $sourcetype = 'supplier_invoice'; - $newtype = 'bank-transfer'; - } - - $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype); - if ($result > 0) - { - $db->commit(); - - setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); - } else { - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); - } - } - $action = ''; - } - - if ($action == "delete") - { - if ($object->id > 0) - { - $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int')); - if ($result == 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&type='.$type); - exit; - } - } - } + if ($action == "new") + { + if ($object->id > 0) + { + $db->begin(); + + $newtype = $type; + $sourcetype = 'facture'; + if ($type == 'bank-transfer') { + $sourcetype = 'supplier_invoice'; + $newtype = 'bank-transfer'; + } + + $result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype); + if ($result > 0) + { + $db->commit(); + + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } + $action = ''; + } + + if ($action == "delete") + { + if ($object->id > 0) + { + $result = $object->demande_prelevement_delete($user, GETPOST('did', 'int')); + if ($result == 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&type='.$type); + exit; + } + } + } } @@ -213,7 +210,7 @@ $head = facture_prepare_head($object); } - print dol_get_fiche_head($head, 'standingorders', $title, -1, ($type == 'bank-transfer' ? 'supplier_invoice' : 'bill')); + dol_fiche_head($head, 'standingorders', $title, -1, 'bill'); // Invoice content if ($type == 'bank-transfer') { @@ -241,37 +238,37 @@ // Project if (!empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref .= '<br>'.$langs->trans('Project').' '; - if ($user->rights->facture->creer) - { - if ($action != 'classify') { - //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; + $langs->load("projects"); + $morehtmlref .= '<br>'.$langs->trans('Project').' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') { + //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; $morehtmlref .= ' : '; } - 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="'.newToken().'">'; - $morehtmlref .= '<input type="hidden" name="type" value="'.$type.'">'; - $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 .= ''; - } - } + 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="'.newToken().'">'; + $morehtmlref .= '<input type="hidden" name="type" value="'.$type.'">'; + $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>'; @@ -381,10 +378,14 @@ if ($action == 'editinvoicedate') { $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $object->date, 'invoicedate'); - } else { + } + else + { print dol_print_date($object->date, 'day'); } - } else { + } + else + { print dol_print_date($object->date, 'day'); } print '</td>'; @@ -403,10 +404,14 @@ if ($action == 'editconditions') { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id'); - } else { + } + else + { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none'); } - } else { + } + else + { print ' '; } print '</td></tr>'; @@ -429,13 +434,17 @@ if ($action == 'editpaymentterm') { $form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $duedate, 'paymentterm'); - } else { + } + else + { print dol_print_date($duedate, 'day'); if ($object->hasDelay()) { print img_warning($langs->trans('Late')); } } - } else { + } + else + { print ' '; } print '</td></tr>'; @@ -451,7 +460,9 @@ if ($action == 'editmode') { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id'); - } else { + } + else + { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); } print '</td></tr>'; @@ -462,14 +473,16 @@ print $langs->trans('BankAccount'); print '<td>'; if (($action != 'editbankaccount') && $user->rights->commande->creer && !empty($object->brouillon)) - print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>'; + print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>'; print '</tr></table>'; print '</td><td colspan="3">'; if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } + else + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); } print "</td>"; print '</tr>'; @@ -503,20 +516,20 @@ if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount HT - print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>'; - print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; - print '</tr>'; - - // Multicurrency Amount VAT - print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>'; - print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; - print '</tr>'; - - // Multicurrency Amount TTC - print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>'; - print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; - print '</tr>'; + // Multicurrency Amount HT + print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>'; + print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; + print '</tr>'; + + // Multicurrency Amount VAT + print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>'; + print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; + print '</tr>'; + + // Multicurrency Amount TTC + print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>'; + print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>'; + print '</tr>'; } // Amount @@ -530,39 +543,39 @@ // Amount Local Taxes if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1 { - print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>'; - print '<td class="nowrap">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>'; + print '<td class="nowrap">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; } if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2 { - print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>'; - print '<td class=nowrap">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>'; + print '<td class=nowrap">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; } // Revenue stamp if ($selleruserevenustamp) // Test company use revenue stamp { - print '<tr><td>'; - print '<table class="nobordernopadding" width="100%"><tr><td>'; - print $langs->trans('RevenueStamp'); - print '</td>'; - if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $user->rights->facture->creer) - { - print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>'; - } - print '</tr></table>'; - print '</td><td>'; - print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency); - print '</td></tr>'; + print '<tr><td>'; + print '<table class="nobordernopadding" width="100%"><tr><td>'; + print $langs->trans('RevenueStamp'); + print '</td>'; + if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $user->rights->facture->creer) + { + print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>'; + } + print '</tr></table>'; + print '</td><td>'; + print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency); + print '</td></tr>'; } // Total with tax print '<tr><td>'.$langs->trans('AmountTTC').'</td><td class="nowrap">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; - $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); - - // TODO Replace this by an include with same code to show already done payment visible in invoice card - print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; + $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); + + // TODO Replace this by an include with same code to show already done payment visible in invoice card + print '<tr><td>'.$langs->trans('RemainderToPay').'</td><td class="nowrap">'.price($resteapayer, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>'; print '</table>'; @@ -573,7 +586,7 @@ print '<div class="clearboth"></div>'; - print dol_get_fiche_end(); + dol_fiche_end(); $numopen = 0; $pending = 0; $numclosed = 0; @@ -599,7 +612,9 @@ { $num = $db->num_rows($result_sql); $numopen = $num; - } else { + } + else + { dol_print_error($db); } @@ -620,7 +635,9 @@ { $obj = $db->fetch_object($result_sql); if ($obj) $pending = $obj->amount; - } else { + } + else + { dol_print_error($db); } @@ -632,44 +649,47 @@ print "\n<div class=\"tabsAction\">\n"; $buttonlabel = $langs->trans("MakeWithdrawRequest"); - $user_perms = $user->rights->prelevement->bons->creer; if ($type == 'bank-transfer') { $buttonlabel = $langs->trans("MakeBankTransferOrder"); - $user_perms = $user->rights->paymentbybanktransfer->create; } // Add a transfer request if ($object->statut > $object::STATUS_DRAFT && $object->paye == 0 && $num == 0) { - if ($resteapayer > 0) - { - if ($user_perms) - { - $remaintopaylesspendingdebit = $resteapayer - $pending; - - print '<form method="POST" action="">'; - print '<input type="hidden" name="token" value="'.newToken().'" />'; - print '<input type="hidden" name="id" value="'.$object->id.'" />'; - print '<input type="hidden" name="type" value="'.$type.'" />'; - print '<input type="hidden" name="action" value="new" />'; - print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>'; - print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />'; - print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />'; - print '</form>'; - } else { - print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>'; - } - } else { - print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>'; - } - } else { + if ($resteapayer > 0) + { + if ($user->rights->prelevement->bons->creer) + { + $remaintopaylesspendingdebit = $resteapayer - $pending; + + print '<form method="POST" action="">'; + print '<input type="hidden" name="token" value="'.newToken().'" />'; + print '<input type="hidden" name="id" value="'.$object->id.'" />'; + print '<input type="hidden" name="type" value="'.$type.'" />'; + print '<input type="hidden" name="action" value="new" />'; + print '<label for="withdraw_request_amount">'.$langs->trans('BankTransferAmount').' </label>'; + print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="'.$remaintopaylesspendingdebit.'" size="9" />'; + print '<input type="submit" class="butAction" value="'.$buttonlabel.'" />'; + print '</form>'; + } + else + { + print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$buttonlabel.'</a>'; + } + } + else + { + print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>'; + } + } + else + { if ($num == 0) { if ($object->statut > $object::STATUS_DRAFT) print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>'; else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>'; - } else { - print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>'; - } + } + else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>'; } print "</div><br>\n"; @@ -754,7 +774,7 @@ print '<td class="center">'.$langs->trans("OrderWaiting").'</td>'; print '<td class="right">'; - print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'&did='.$obj->rowid.'&type='.$type.'">'; + print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&did='.$obj->rowid.'&type='.$type.'">'; print img_delete(); print '</a></td>'; @@ -763,7 +783,9 @@ } $db->free($result_sql); - } else { + } + else + { dol_print_error($db); } @@ -840,7 +862,9 @@ print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; $db->free($result); - } else { + } + else + { dol_print_error($db); }