';
echo '
';
echo '
';
@@ -1460,401 +1460,401 @@ $db->close();
*/
function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
{
- global $user, $conf, $langs;
- global $action, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
- global $theme_datacolor;
- global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
+ global $user, $conf, $langs;
+ global $action, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
+ global $theme_datacolor;
+ global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
- $dateint = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
+ $dateint = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
- print "\n";
+ print "\n";
- // Line with title of day
- $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
- print '
'."\n";
+ // Line with title of day
+ $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
+ print '
'."\n";
- if ($nonew <= 0)
- {
- print '
';
- if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
- {
- $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
+ if ($nonew <= 0)
+ {
+ print '
'."\n";
- }
+ //$param='month='.$monthshown.'&year='.$year;
+ $hourminsec = '100000';
+ print '
';
+ print img_picto($langs->trans("NewAction"), 'edit_add.png');
+ print '';
+ }
+ print '
'."\n";
+ }
- if ($nonew < 0)
- {
- print '
';
- return;
- }
+ if ($nonew < 0)
+ {
+ print '
';
+ return;
+ }
- // Line with td contains all div of each events
- print '
';
- print '
';
+ // Line with td contains all div of each events
+ print '
';
+ print '
';
- //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
- $i = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
- $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
+ //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
+ $i = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
+ $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
- $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
- $nextindextouse = is_array($colorindexused) ?count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
+ $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
+ $nextindextouse = is_array($colorindexused) ?count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
//var_dump($colorindexused);
- foreach ($eventarray as $daykey => $notused)
- {
- $annee = date('Y', $daykey);
- $mois = date('m', $daykey);
- $jour = date('d', $daykey);
- if ($day == $jour && $month == $mois && $year == $annee)
- {
- foreach ($eventarray[$daykey] as $index => $event)
- {
- if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA))
- {
- $keysofuserassigned = array_keys($event->userassigned);
- $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
+ foreach ($eventarray as $daykey => $notused)
+ {
+ $annee = date('Y', $daykey);
+ $mois = date('m', $daykey);
+ $jour = date('d', $daykey);
+ if ($day == $jour && $month == $mois && $year == $annee)
+ {
+ foreach ($eventarray[$daykey] as $index => $event)
+ {
+ if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA))
+ {
+ $keysofuserassigned = array_keys($event->userassigned);
+ $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
- // Define $color (Hex string like '0088FF') and $cssclass of event
- $color = -1; $cssclass = ''; $colorindex = -1;
- if (in_array($user->id, $keysofuserassigned))
- {
- $cssclass = 'family_mytasks';
+ // Define $color (Hex string like '0088FF') and $cssclass of event
+ $color = -1; $cssclass = ''; $colorindex = -1;
+ if (in_array($user->id, $keysofuserassigned))
+ {
+ $cssclass = 'family_mytasks';
- if (empty($cacheusers[$event->userownerid]))
- {
- $newuser = new User($db);
- $newuser->fetch($event->userownerid);
- $cacheusers[$event->userownerid] = $newuser;
- }
- //var_dump($cacheusers[$event->userownerid]->color);
+ if (empty($cacheusers[$event->userownerid]))
+ {
+ $newuser = new User($db);
+ $newuser->fetch($event->userownerid);
+ $cacheusers[$event->userownerid] = $newuser;
+ }
+ //var_dump($cacheusers[$event->userownerid]->color);
- // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
- if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
- } elseif ($event->type_code == 'ICALEVENT') // Event come from external ical file
- {
- $numical++;
- if (!empty($event->icalname)) {
- if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
- $numicals[dol_string_nospecial($event->icalname)] = 0;
- }
- $numicals[dol_string_nospecial($event->icalname)]++;
- }
+ // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
+ if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
+ } elseif ($event->type_code == 'ICALEVENT') // Event come from external ical file
+ {
+ $numical++;
+ if (!empty($event->icalname)) {
+ if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
+ $numicals[dol_string_nospecial($event->icalname)] = 0;
+ }
+ $numicals[dol_string_nospecial($event->icalname)]++;
+ }
- $color = ($event->icalcolor ? $event->icalcolor : -1);
- $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
- } elseif ($event->type_code == 'BIRTHDAY')
- {
- $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unmovable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
- } else {
- $numother++;
- $color = ($event->icalcolor ? $event->icalcolor : -1);
- $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
+ $color = ($event->icalcolor ? $event->icalcolor : -1);
+ $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
+ } elseif ($event->type_code == 'BIRTHDAY')
+ {
+ $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unmovable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
+ } else {
+ $numother++;
+ $color = ($event->icalcolor ? $event->icalcolor : -1);
+ $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
- if (empty($cacheusers[$event->userownerid]))
- {
- $newuser = new User($db);
- $newuser->fetch($event->userownerid);
- $cacheusers[$event->userownerid] = $newuser;
- }
- //var_dump($cacheusers[$event->userownerid]->color);
+ if (empty($cacheusers[$event->userownerid]))
+ {
+ $newuser = new User($db);
+ $newuser->fetch($event->userownerid);
+ $cacheusers[$event->userownerid] = $newuser;
+ }
+ //var_dump($cacheusers[$event->userownerid]->color);
- // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
- if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
- }
+ // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
+ if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
+ }
- if ($color < 0) // Color was not set on user card. Set color according to color index.
- {
- // Define color index if not yet defined
- $idusertouse = ($event->userownerid ? $event->userownerid : 0);
- if (isset($colorindexused[$idusertouse]))
- {
- $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
- } else {
- $colorindex = $nextindextouse;
- $colorindexused[$idusertouse] = $colorindex;
- if (!empty($theme_datacolor[$nextindextouse + 1])) $nextindextouse++; // Prepare to use next color
- }
- //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'
';
- // Define color
- $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
- }
- $cssclass = $cssclass.' '.$cssclass.'_day_'.$ymd;
+ if ($color < 0) // Color was not set on user card. Set color according to color index.
+ {
+ // Define color index if not yet defined
+ $idusertouse = ($event->userownerid ? $event->userownerid : 0);
+ if (isset($colorindexused[$idusertouse]))
+ {
+ $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
+ } else {
+ $colorindex = $nextindextouse;
+ $colorindexused[$idusertouse] = $colorindex;
+ if (!empty($theme_datacolor[$nextindextouse + 1])) $nextindextouse++; // Prepare to use next color
+ }
+ //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'
';
+ // Define color
+ $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
+ }
+ $cssclass = $cssclass.' '.$cssclass.'_day_'.$ymd;
- // Defined style to disable drag and drop feature
- if ($event->type_code == 'AC_OTH_AUTO')
- {
- $cssclass .= " unmovable";
- } elseif ($event->type_code == 'ICALEVENT')
- {
- $cssclass .= " unmovable";
- } elseif ($event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
- $tmpyearend = date('Y', $event->date_end_in_calendar);
- $tmpmonthend = date('m', $event->date_end_in_calendar);
- $tmpdayend = date('d', $event->date_end_in_calendar);
- if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
- {
- $cssclass .= " unmovable";
- }
- } else {
- if ($user->rights->agenda->allactions->create ||
- (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create))
- {
- $cssclass .= " movable cursormove";
- } else {
- $cssclass .= " unmovable";
- }
- }
+ // Defined style to disable drag and drop feature
+ if ($event->type_code == 'AC_OTH_AUTO')
+ {
+ $cssclass .= " unmovable";
+ } elseif ($event->type_code == 'ICALEVENT')
+ {
+ $cssclass .= " unmovable";
+ } elseif ($event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
+ $tmpyearend = date('Y', $event->date_end_in_calendar);
+ $tmpmonthend = date('m', $event->date_end_in_calendar);
+ $tmpdayend = date('d', $event->date_end_in_calendar);
+ if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
+ {
+ $cssclass .= " unmovable";
+ }
+ } else {
+ if ($user->rights->agenda->allactions->create ||
+ (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create))
+ {
+ $cssclass .= " movable cursormove";
+ } else {
+ $cssclass .= " unmovable";
+ }
+ }
- $h = ''; $nowrapontd = 1;
- if ($action == 'show_day') { $h = 'height: 100%; '; $nowrapontd = 0; }
- if ($action == 'show_week') { $h = 'height: 100%; '; $nowrapontd = 0; }
+ $h = ''; $nowrapontd = 1;
+ if ($action == 'show_day') { $h = 'height: 100%; '; $nowrapontd = 0; }
+ if ($action == 'show_week') { $h = 'height: 100%; '; $nowrapontd = 0; }
- // Show rect of event
- print "\n";
- print ''."\n";
- print '
';
+ // Show rect of event
+ print "\n";
+ print ''."\n";
+ print '
';
- //var_dump($event->userassigned);
- //var_dump($event->transparency);
- print '
';
- print '';
- print '';
+ //var_dump($event->userassigned);
+ //var_dump($event->transparency);
+ print '';
+ print '';
+ print '';
- $daterange = '';
+ $daterange = '';
- if ($event->type_code == 'BIRTHDAY') // It's a birthday
- {
- print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
- } elseif ($event->type_code == 'HOLIDAY')
- {
- print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'holiday', 'user');
- } elseif ($event->type_code != 'BIRTHDAY' && $event->type_code != 'HOLIDAY')
- {
- // Picto
- if (empty($event->fulldayevent))
- {
- //print $event->getNomUrl(2).' ';
- }
+ if ($event->type_code == 'BIRTHDAY') // It's a birthday
+ {
+ print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
+ } elseif ($event->type_code == 'HOLIDAY')
+ {
+ print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'holiday', 'user');
+ } elseif ($event->type_code != 'BIRTHDAY' && $event->type_code != 'HOLIDAY')
+ {
+ // Picto
+ if (empty($event->fulldayevent))
+ {
+ //print $event->getNomUrl(2).' ';
+ }
- // Date
- if (empty($event->fulldayevent))
- {
- // Show hours (start ... end)
- $tmpyearstart = date('Y', $event->date_start_in_calendar);
- $tmpmonthstart = date('m', $event->date_start_in_calendar);
- $tmpdaystart = date('d', $event->date_start_in_calendar);
- $tmpyearend = date('Y', $event->date_end_in_calendar);
- $tmpmonthend = date('m', $event->date_end_in_calendar);
- $tmpdayend = date('d', $event->date_end_in_calendar);
- // Hour start
- if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
- {
- $daterange .= dol_print_date($event->date_start_in_calendar, 'hour'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
- if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
- {
- if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
- $daterange .= '-';
- //else
- //print '...';
- }
- }
- if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
- {
- if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
- {
- $daterange .= '...';
- }
- }
- // Hour end
- if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
- {
- if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
- $daterange .= dol_print_date($event->date_end_in_calendar, 'hour'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
- }
- } else {
- if ($showinfo)
- {
- print $langs->trans("EventOnFullDay")." \n";
- }
- }
+ // Date
+ if (empty($event->fulldayevent))
+ {
+ // Show hours (start ... end)
+ $tmpyearstart = date('Y', $event->date_start_in_calendar);
+ $tmpmonthstart = date('m', $event->date_start_in_calendar);
+ $tmpdaystart = date('d', $event->date_start_in_calendar);
+ $tmpyearend = date('Y', $event->date_end_in_calendar);
+ $tmpmonthend = date('m', $event->date_end_in_calendar);
+ $tmpdayend = date('d', $event->date_end_in_calendar);
+ // Hour start
+ if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
+ {
+ $daterange .= dol_print_date($event->date_start_in_calendar, 'hour'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
+ if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
+ {
+ if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
+ $daterange .= '-';
+ //else
+ //print '...';
+ }
+ }
+ if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
+ {
+ if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
+ {
+ $daterange .= '...';
+ }
+ }
+ // Hour end
+ if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
+ {
+ if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
+ $daterange .= dol_print_date($event->date_end_in_calendar, 'hour'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
+ }
+ } else {
+ if ($showinfo)
+ {
+ print $langs->trans("EventOnFullDay")." \n";
+ }
+ }
- // Show title
- $titletoshow = $daterange;
- $titletoshow .= ($titletoshow ? ' ' : '').($event->label ? $event->label : $event->libelle);
+ // Show title
+ $titletoshow = $daterange;
+ $titletoshow .= ($titletoshow ? ' ' : '').($event->label ? $event->label : $event->libelle);
- if ($event->type_code != 'ICALEVENT') {
- $savlabel = $event->label ? $event->label : $event->libelle;
- $event->label = $titletoshow;
- $event->libelle = $titletoshow;
- // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
- $titletoshow = $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
- $event->label = $savlabel;
- $event->libelle = $savlabel;
- }
+ if ($event->type_code != 'ICALEVENT') {
+ $savlabel = $event->label ? $event->label : $event->libelle;
+ $event->label = $titletoshow;
+ $event->libelle = $titletoshow;
+ // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
+ $titletoshow = $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
+ $event->label = $savlabel;
+ $event->libelle = $savlabel;
+ }
- // Loop on each assigned user
- $listofusertoshow = '';
- $posuserassigned = 0;
- foreach ($event->userassigned as $tmpid => $tmpdata)
- {
- if (!$posuserassigned && $titletoshow) $listofusertoshow .= ' ';
- $posuserassigned++;
- if (empty($cacheusers[$tmpid]))
- {
- $newuser = new User($db);
- $newuser->fetch($tmpid);
- $cacheusers[$tmpid] = $newuser;
- }
+ // Loop on each assigned user
+ $listofusertoshow = '';
+ $posuserassigned = 0;
+ foreach ($event->userassigned as $tmpid => $tmpdata)
+ {
+ if (!$posuserassigned && $titletoshow) $listofusertoshow .= ' ';
+ $posuserassigned++;
+ if (empty($cacheusers[$tmpid]))
+ {
+ $newuser = new User($db);
+ $newuser->fetch($tmpid);
+ $cacheusers[$tmpid] = $newuser;
+ }
- $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
- }
+ $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
+ }
- print $titletoshow;
- print $listofusertoshow;
+ print $titletoshow;
+ print $listofusertoshow;
- if ($event->type_code == 'ICALEVENT') print ' ('.dol_trunc($event->icalname, $maxnbofchar).')';
+ if ($event->type_code == 'ICALEVENT') print ' ('.dol_trunc($event->icalname, $maxnbofchar).')';
- $thirdparty_id = ($event->thirdparty_id > 0 ? $event->thirdparty_id : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
- $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
+ $thirdparty_id = ($event->thirdparty_id > 0 ? $event->thirdparty_id : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
+ $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
- // If action related to company / contact
- $linerelatedto = '';
- if ($thirdparty_id > 0)
- {
- if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id]))
- {
- $thirdparty = new Societe($db);
- $thirdparty->fetch($thirdparty_id);
- $cachethirdparties[$thirdparty_id] = $thirdparty;
- } else $thirdparty = $cachethirdparties[$thirdparty_id];
- if (!empty($thirdparty->id)) $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
- }
- if (!empty($contact_id) && $contact_id > 0)
- {
- if (!is_object($cachecontacts[$contact_id]))
- {
- $contact = new Contact($db);
- $contact->fetch($contact_id);
- $cachecontacts[$contact_id] = $contact;
- } else $contact = $cachecontacts[$contact_id];
- if ($linerelatedto) $linerelatedto .= ' ';
- if (!empty($contact->id)) $linerelatedto .= $contact->getNomUrl(1, '', 0);
- }
- if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))
- {
- include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
- if ($linerelatedto) $linerelatedto .= ' ';
- $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
- }
- if ($linerelatedto) print ' '.$linerelatedto;
- }
+ // If action related to company / contact
+ $linerelatedto = '';
+ if ($thirdparty_id > 0)
+ {
+ if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id]))
+ {
+ $thirdparty = new Societe($db);
+ $thirdparty->fetch($thirdparty_id);
+ $cachethirdparties[$thirdparty_id] = $thirdparty;
+ } else $thirdparty = $cachethirdparties[$thirdparty_id];
+ if (!empty($thirdparty->id)) $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
+ }
+ if (!empty($contact_id) && $contact_id > 0)
+ {
+ if (!is_object($cachecontacts[$contact_id]))
+ {
+ $contact = new Contact($db);
+ $contact->fetch($contact_id);
+ $cachecontacts[$contact_id] = $contact;
+ } else $contact = $cachecontacts[$contact_id];
+ if ($linerelatedto) $linerelatedto .= ' ';
+ if (!empty($contact->id)) $linerelatedto .= $contact->getNomUrl(1, '', 0);
+ }
+ if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))
+ {
+ include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+ if ($linerelatedto) $linerelatedto .= ' ';
+ $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
+ }
+ if ($linerelatedto) print ' '.$linerelatedto;
+ }
- // Show location
- if ($showinfo)
- {
- if ($event->location)
- {
- print ' ';
- print $langs->trans("Location").': '.$event->location;
- }
- }
+ // Show location
+ if ($showinfo)
+ {
+ if ($event->location)
+ {
+ print ' ';
+ print $langs->trans("Location").': '.$event->location;
+ }
+ }
- print ' | ';
- // Status - Percent
- $withstatus = 0;
- if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT')
- {
- $withstatus = 1;
- if ($event->percentage >= 0) $withstatus = 2;
- }
- print '';
- if ($withstatus) print $event->getLibStatut(3, 1);
- else print ' ';
- print ' | ';
- print ''."\n";
- $i++;
- } else {
- print ''.img_picto("all", "1downarrow_selected.png").' ...';
- print ' +'.(count($eventarray[$daykey]) - $maxprint);
- print '';
- break;
- //$ok=false; // To avoid to show twice the link
- }
- }
+ print ' | ';
+ // Status - Percent
+ $withstatus = 0;
+ if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT')
+ {
+ $withstatus = 1;
+ if ($event->percentage >= 0) $withstatus = 2;
+ }
+ print '';
+ if ($withstatus) print $event->getLibStatut(3, 1);
+ else print ' ';
+ print ' |
';
+ print '
'."\n";
+ $i++;
+ } else {
+ print '
'.img_picto("all", "1downarrow_selected.png").' ...';
+ print ' +'.(count($eventarray[$daykey]) - $maxprint);
+ print '';
+ break;
+ //$ok=false; // To avoid to show twice the link
+ }
+ }
- break;
- }
- }
- if (!$i) print ' ';
+ break;
+ }
+ }
+ if (!$i) print ' ';
- if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint)
- {
- print '
'.img_picto("all", "1downarrow_selected.png").' +'.$langs->trans("More").'...
';
- //print ' +'.(count($eventarray[$daykey])-$maxprint);
- print ''."\n";
- }
+ print ''."\n";
+ }
- print '
'; // td tr
+ print '
'; // td tr
- print '
'; // table
- print "\n";
+ print '
'; // table
+ print "\n";
}
diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php
index db59fd5f942..7bce96633fc 100644
--- a/htdocs/comm/propal/list.php
+++ b/htdocs/comm/propal/list.php
@@ -1291,21 +1291,21 @@ if ($resql)
foreach ($toselect as $checked) {
if ($tmpproposal->fetch($checked)) {
if ($tmpproposal->statut == 0) {
- if ($tmpproposal->valid($user)){
- setEventMessage($tmpproposal->ref . " " . $langs->trans('PassedInOpenStatus'), 'mesgs');
+ if ($tmpproposal->valid($user)) {
+ setEventMessage($tmpproposal->ref." ".$langs->trans('PassedInOpenStatus'), 'mesgs');
} else {
setEventMessage($langs->trans('CantBeValidated'), 'errors');
$error++;
}
} else {
- setEventMessage($tmpproposal->ref . " " . $langs->trans('IsNotADraft'), 'errors');
+ setEventMessage($tmpproposal->ref." ".$langs->trans('IsNotADraft'), 'errors');
$error++;
}
}
dol_print_error($db);
$error++;
}
- if ($error){
+ if ($error) {
$db->rollback();
} else {
$db->commit();
@@ -1323,13 +1323,13 @@ if ($resql)
if ($tmpproposal->statut == 1) {
$tmpproposal->statut = 2;
if ($tmpproposal->update($user)) {
- setEventMessage($tmpproposal->ref . " " . $langs->trans('Signed'), 'mesgs');
+ setEventMessage($tmpproposal->ref." ".$langs->trans('Signed'), 'mesgs');
} else {
dol_print_error($db);
$error++;
}
} else {
- setEventMessage($tmpproposal->ref . " " . $langs->trans('CantBeSign'), 'errors');
+ setEventMessage($tmpproposal->ref." ".$langs->trans('CantBeSign'), 'errors');
$error++;
}
} else {
@@ -1337,7 +1337,7 @@ if ($resql)
$error++;
}
}
- if ($error){
+ if ($error) {
$db->rollback();
} else {
$db->commit();
diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php
index e4d432b234a..75f9457b45f 100644
--- a/htdocs/commande/class/api_orders.class.php
+++ b/htdocs/commande/class/api_orders.class.php
@@ -29,229 +29,229 @@ require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
class Orders extends DolibarrApi
{
- /**
- * @var array $FIELDS Mandatory fields, checked when create and update object
- */
- static $FIELDS = array(
- 'socid',
- 'date'
- );
+ /**
+ * @var array $FIELDS Mandatory fields, checked when create and update object
+ */
+ static $FIELDS = array(
+ 'socid',
+ 'date'
+ );
- /**
- * @var Commande $commande {@type Commande}
- */
- public $commande;
+ /**
+ * @var Commande $commande {@type Commande}
+ */
+ public $commande;
- /**
- * Constructor
- */
- public function __construct()
- {
- global $db, $conf;
- $this->db = $db;
- $this->commande = new Commande($this->db);
- }
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ global $db, $conf;
+ $this->db = $db;
+ $this->commande = new Commande($this->db);
+ }
- /**
- * Get properties of an order object by id
- *
- * Return an array with order informations
- *
- * @param int $id ID of order
- * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
- * @return array|mixed data without useless information
+ /**
+ * Get properties of an order object by id
*
- * @throws RestException
- */
- public function get($id, $contact_list = 1)
- {
- return $this->_fetch($id, '', '', $contact_list);
- }
+ * Return an array with order informations
+ *
+ * @param int $id ID of order
+ * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
+ * @return array|mixed data without useless information
+ *
+ * @throws RestException
+ */
+ public function get($id, $contact_list = 1)
+ {
+ return $this->_fetch($id, '', '', $contact_list);
+ }
- /**
- * Get properties of an order object by ref
- *
- * Return an array with order informations
- *
- * @param string $ref Ref of object
- * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
- * @return array|mixed data without useless information
- *
- * @url GET ref/{ref}
- *
- * @throws RestException
- */
- public function getByRef($ref, $contact_list = 1)
- {
- return $this->_fetch('', $ref, '', $contact_list);
- }
+ /**
+ * Get properties of an order object by ref
+ *
+ * Return an array with order informations
+ *
+ * @param string $ref Ref of object
+ * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
+ * @return array|mixed data without useless information
+ *
+ * @url GET ref/{ref}
+ *
+ * @throws RestException
+ */
+ public function getByRef($ref, $contact_list = 1)
+ {
+ return $this->_fetch('', $ref, '', $contact_list);
+ }
- /**
- * Get properties of an order object by ref_ext
- *
- * Return an array with order informations
- *
- * @param string $ref_ext External reference of object
- * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
- * @return array|mixed data without useless information
- *
- * @url GET ref_ext/{ref_ext}
- *
- * @throws RestException
- */
- public function getByRefExt($ref_ext, $contact_list = 1)
- {
- return $this->_fetch('', '', $ref_ext, $contact_list);
- }
+ /**
+ * Get properties of an order object by ref_ext
+ *
+ * Return an array with order informations
+ *
+ * @param string $ref_ext External reference of object
+ * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
+ * @return array|mixed data without useless information
+ *
+ * @url GET ref_ext/{ref_ext}
+ *
+ * @throws RestException
+ */
+ public function getByRefExt($ref_ext, $contact_list = 1)
+ {
+ return $this->_fetch('', '', $ref_ext, $contact_list);
+ }
- /**
- * Get properties of an order object
- *
- * Return an array with order informations
- *
- * @param int $id ID of order
+ /**
+ * Get properties of an order object
+ *
+ * Return an array with order informations
+ *
+ * @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
- * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
- * @return array|mixed data without useless information
- *
- * @throws RestException
- */
- private function _fetch($id, $ref = '', $ref_ext = '', $contact_list = 1)
- {
- if (!DolibarrApiAccess::$user->rights->commande->lire) {
- throw new RestException(401);
- }
+ * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
+ * @return array|mixed data without useless information
+ *
+ * @throws RestException
+ */
+ private function _fetch($id, $ref = '', $ref_ext = '', $contact_list = 1)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->lire) {
+ throw new RestException(401);
+ }
- $result = $this->commande->fetch($id, $ref, $ref_ext);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id, $ref, $ref_ext);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
- // Add external contacts ids
- $this->commande->contacts_ids = $this->commande->liste_contact(-1, 'external', $contact_list);
- $this->commande->fetchObjectLinked();
- return $this->_cleanObjectDatas($this->commande);
- }
+ // Add external contacts ids
+ $this->commande->contacts_ids = $this->commande->liste_contact(-1, 'external', $contact_list);
+ $this->commande->fetchObjectLinked();
+ return $this->_cleanObjectDatas($this->commande);
+ }
- /**
- * List orders
- *
- * Get a list of orders
- *
- * @param string $sortfield Sort field
- * @param string $sortorder Sort order
- * @param int $limit Limit for list
- * @param int $page Page number
- * @param string $thirdparty_ids Thirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
- * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
- * @return array Array of order objects
- *
- * @throws RestException 404 Not found
- * @throws RestException 503 Error
- */
- public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '')
- {
- global $db, $conf;
+ /**
+ * List orders
+ *
+ * Get a list of orders
+ *
+ * @param string $sortfield Sort field
+ * @param string $sortorder Sort order
+ * @param int $limit Limit for list
+ * @param int $page Page number
+ * @param string $thirdparty_ids Thirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i}
+ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
+ * @return array Array of order objects
+ *
+ * @throws RestException 404 Not found
+ * @throws RestException 503 Error
+ */
+ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '')
+ {
+ global $db, $conf;
- $obj_ret = array();
+ $obj_ret = array();
- // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
- $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
+ // case of external user, $thirdparty_ids param is ignored and replaced by user's socid
+ $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
- // If the internal user must only see his customers, force searching by him
- $search_sale = 0;
- if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
+ // If the internal user must only see his customers, force searching by him
+ $search_sale = 0;
+ if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
- $sql = "SELECT t.rowid";
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
- $sql .= " FROM ".MAIN_DB_PREFIX."commande as t";
+ $sql = "SELECT t.rowid";
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
+ $sql .= " FROM ".MAIN_DB_PREFIX."commande as t";
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
- $sql .= ' WHERE t.entity IN ('.getEntity('commande').')';
- if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
- if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
- if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
- // Insert sale filter
- if ($search_sale > 0)
- {
- $sql .= " AND sc.fk_user = ".$search_sale;
- }
- // Add sql filters
- if ($sqlfilters)
- {
- if (!DolibarrApi::_checkFilters($sqlfilters))
- {
- throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
- }
- $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
- $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
- }
+ $sql .= ' WHERE t.entity IN ('.getEntity('commande').')';
+ if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
+ if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
+ if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
+ // Insert sale filter
+ if ($search_sale > 0)
+ {
+ $sql .= " AND sc.fk_user = ".$search_sale;
+ }
+ // Add sql filters
+ if ($sqlfilters)
+ {
+ if (!DolibarrApi::_checkFilters($sqlfilters))
+ {
+ throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+ }
+ $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+ $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+ }
- $sql .= $db->order($sortfield, $sortorder);
- if ($limit) {
- if ($page < 0)
- {
- $page = 0;
- }
- $offset = $limit * $page;
+ $sql .= $db->order($sortfield, $sortorder);
+ if ($limit) {
+ if ($page < 0)
+ {
+ $page = 0;
+ }
+ $offset = $limit * $page;
- $sql .= $db->plimit($limit + 1, $offset);
- }
+ $sql .= $db->plimit($limit + 1, $offset);
+ }
- dol_syslog("API Rest request");
- $result = $db->query($sql);
+ dol_syslog("API Rest request");
+ $result = $db->query($sql);
- if ($result)
- {
- $num = $db->num_rows($result);
- $min = min($num, ($limit <= 0 ? $num : $limit));
- $i = 0;
- while ($i < $min)
- {
- $obj = $db->fetch_object($result);
- $commande_static = new Commande($db);
- if ($commande_static->fetch($obj->rowid)) {
- // Add external contacts ids
- $commande_static->contacts_ids = $commande_static->liste_contact(-1, 'external', 1);
- $obj_ret[] = $this->_cleanObjectDatas($commande_static);
- }
- $i++;
- }
- } else {
- throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
- }
- if (!count($obj_ret)) {
- throw new RestException(404, 'No order found');
- }
+ if ($result)
+ {
+ $num = $db->num_rows($result);
+ $min = min($num, ($limit <= 0 ? $num : $limit));
+ $i = 0;
+ while ($i < $min)
+ {
+ $obj = $db->fetch_object($result);
+ $commande_static = new Commande($db);
+ if ($commande_static->fetch($obj->rowid)) {
+ // Add external contacts ids
+ $commande_static->contacts_ids = $commande_static->liste_contact(-1, 'external', 1);
+ $obj_ret[] = $this->_cleanObjectDatas($commande_static);
+ }
+ $i++;
+ }
+ } else {
+ throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
+ }
+ if (!count($obj_ret)) {
+ throw new RestException(404, 'No order found');
+ }
return $obj_ret;
- }
+ }
- /**
- * Create a sale order
- *
- * Exemple: { "socid": 2, "date": 1595196000, "type": 0, "lines": [{ "fk_product": 2, "qty": 1 }] }
- *
- * @param array $request_data Request data
- * @return int ID of order
- */
- public function post($request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ /**
+ * Create a sale order
+ *
+ * Exemple: { "socid": 2, "date": 1595196000, "type": 0, "lines": [{ "fk_product": 2, "qty": 1 }] }
+ *
+ * @param array $request_data Request data
+ * @return int ID of order
+ */
+ public function post($request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401, "Insuffisant rights");
- }
- // Check mandatory fields
- $result = $this->_validate($request_data);
+ }
+ // Check mandatory fields
+ $result = $this->_validate($request_data);
- foreach ($request_data as $field => $value) {
- $this->commande->$field = $value;
- }
- /*if (isset($request_data["lines"])) {
+ foreach ($request_data as $field => $value) {
+ $this->commande->$field = $value;
+ }
+ /*if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
@@ -259,241 +259,241 @@ class Orders extends DolibarrApi
$this->commande->lines = $lines;
}*/
- if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
- throw new RestException(500, "Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
- }
+ if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
+ throw new RestException(500, "Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
+ }
- return $this->commande->id;
- }
+ return $this->commande->id;
+ }
- /**
- * Get lines of an order
- *
- * @param int $id Id of order
- *
- * @url GET {id}/lines
- *
- * @return int
- */
- public function getLines($id)
- {
- if (!DolibarrApiAccess::$user->rights->commande->lire) {
+ /**
+ * Get lines of an order
+ *
+ * @param int $id Id of order
+ *
+ * @url GET {id}/lines
+ *
+ * @return int
+ */
+ public function getLines($id)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
- $this->commande->getLinesArray();
- $result = array();
- foreach ($this->commande->lines as $line) {
- array_push($result, $this->_cleanObjectDatas($line));
- }
- return $result;
- }
+ }
+ $this->commande->getLinesArray();
+ $result = array();
+ foreach ($this->commande->lines as $line) {
+ array_push($result, $this->_cleanObjectDatas($line));
+ }
+ return $result;
+ }
- /**
- * Add a line to given order
- *
- * @param int $id Id of order to update
- * @param array $request_data OrderLine data
- *
- * @url POST {id}/lines
- *
- * @return int
- */
- public function postLine($id, $request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ /**
+ * Add a line to given order
+ *
+ * @param int $id Id of order to update
+ * @param array $request_data OrderLine data
+ *
+ * @url POST {id}/lines
+ *
+ * @return int
+ */
+ public function postLine($id, $request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ }
$request_data = (object) $request_data;
- $updateRes = $this->commande->addline(
- $request_data->desc,
- $request_data->subprice,
- $request_data->qty,
- $request_data->tva_tx,
- $request_data->localtax1_tx,
- $request_data->localtax2_tx,
- $request_data->fk_product,
- $request_data->remise_percent,
- $request_data->info_bits,
- $request_data->fk_remise_except,
- 'HT',
- 0,
- $request_data->date_start,
- $request_data->date_end,
- $request_data->product_type,
- $request_data->rang,
- $request_data->special_code,
- $request_data->fk_parent_line,
- $request_data->fk_fournprice,
- $request_data->pa_ht,
- $request_data->label,
- $request_data->array_options,
- $request_data->fk_unit,
- $request_data->origin,
- $request_data->origin_id,
- $request_data->multicurrency_subprice,
- $request_data->ref_ext
- );
+ $updateRes = $this->commande->addline(
+ $request_data->desc,
+ $request_data->subprice,
+ $request_data->qty,
+ $request_data->tva_tx,
+ $request_data->localtax1_tx,
+ $request_data->localtax2_tx,
+ $request_data->fk_product,
+ $request_data->remise_percent,
+ $request_data->info_bits,
+ $request_data->fk_remise_except,
+ 'HT',
+ 0,
+ $request_data->date_start,
+ $request_data->date_end,
+ $request_data->product_type,
+ $request_data->rang,
+ $request_data->special_code,
+ $request_data->fk_parent_line,
+ $request_data->fk_fournprice,
+ $request_data->pa_ht,
+ $request_data->label,
+ $request_data->array_options,
+ $request_data->fk_unit,
+ $request_data->origin,
+ $request_data->origin_id,
+ $request_data->multicurrency_subprice,
+ $request_data->ref_ext
+ );
- if ($updateRes > 0) {
- return $updateRes;
- } else {
- throw new RestException(400, $this->commande->error);
- }
- }
+ if ($updateRes > 0) {
+ return $updateRes;
+ } else {
+ throw new RestException(400, $this->commande->error);
+ }
+ }
- /**
- * Update a line to given order
- *
- * @param int $id Id of order to update
- * @param int $lineid Id of line to update
- * @param array $request_data OrderLine data
- *
- * @url PUT {id}/lines/{lineid}
- *
- * @return array|bool
- */
- public function putLine($id, $lineid, $request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ /**
+ * Update a line to given order
+ *
+ * @param int $id Id of order to update
+ * @param int $lineid Id of line to update
+ * @param array $request_data OrderLine data
+ *
+ * @url PUT {id}/lines/{lineid}
+ *
+ * @return array|bool
+ */
+ public function putLine($id, $lineid, $request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ }
$request_data = (object) $request_data;
- $updateRes = $this->commande->updateline(
- $lineid,
- $request_data->desc,
- $request_data->subprice,
- $request_data->qty,
- $request_data->remise_percent,
- $request_data->tva_tx,
- $request_data->localtax1_tx,
- $request_data->localtax2_tx,
- 'HT',
- $request_data->info_bits,
- $request_data->date_start,
- $request_data->date_end,
- $request_data->product_type,
- $request_data->fk_parent_line,
- 0,
- $request_data->fk_fournprice,
- $request_data->pa_ht,
- $request_data->label,
- $request_data->special_code,
- $request_data->array_options,
- $request_data->fk_unit,
- $request_data->multicurrency_subprice,
+ $updateRes = $this->commande->updateline(
+ $lineid,
+ $request_data->desc,
+ $request_data->subprice,
+ $request_data->qty,
+ $request_data->remise_percent,
+ $request_data->tva_tx,
+ $request_data->localtax1_tx,
+ $request_data->localtax2_tx,
+ 'HT',
+ $request_data->info_bits,
+ $request_data->date_start,
+ $request_data->date_end,
+ $request_data->product_type,
+ $request_data->fk_parent_line,
0,
- $request_data->ref_ext
- );
+ $request_data->fk_fournprice,
+ $request_data->pa_ht,
+ $request_data->label,
+ $request_data->special_code,
+ $request_data->array_options,
+ $request_data->fk_unit,
+ $request_data->multicurrency_subprice,
+ 0,
+ $request_data->ref_ext
+ );
- if ($updateRes > 0) {
- $result = $this->get($id);
- unset($result->line);
- return $this->_cleanObjectDatas($result);
- }
- return false;
- }
+ if ($updateRes > 0) {
+ $result = $this->get($id);
+ unset($result->line);
+ return $this->_cleanObjectDatas($result);
+ }
+ return false;
+ }
- /**
- * Delete a line to given order
- *
- *
- * @param int $id Id of order to update
- * @param int $lineid Id of line to delete
- *
- * @url DELETE {id}/lines/{lineid}
- *
- * @return int
- *
- * @throws RestException 401
- * @throws RestException 404
- */
- public function deleteLine($id, $lineid)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ /**
+ * Delete a line to given order
+ *
+ *
+ * @param int $id Id of order to update
+ * @param int $lineid Id of line to delete
+ *
+ * @url DELETE {id}/lines/{lineid}
+ *
+ * @return int
+ *
+ * @throws RestException 401
+ * @throws RestException 404
+ */
+ public function deleteLine($id, $lineid)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ }
- // TODO Check the lineid $lineid is a line of ojbect
+ // TODO Check the lineid $lineid is a line of ojbect
- $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user, $lineid);
- if ($updateRes > 0) {
- return $this->get($id);
- } else {
- throw new RestException(405, $this->commande->error);
- }
- }
+ $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user, $lineid);
+ if ($updateRes > 0) {
+ return $this->get($id);
+ } else {
+ throw new RestException(405, $this->commande->error);
+ }
+ }
- /**
- * Get contacts of given order
- *
- * Return an array with contact informations
- *
- * @param int $id ID of order
+ /**
+ * Get contacts of given order
+ *
+ * Return an array with contact informations
+ *
+ * @param int $id ID of order
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER)
- *
- * @url GET {id}/contacts
- *
- * @return array data without useless information
- *
- * @throws RestException
- */
- public function getContacts($id, $type = '')
- {
- if (! DolibarrApiAccess::$user->rights->commande->lire) {
- throw new RestException(401);
- }
+ *
+ * @url GET {id}/contacts
+ *
+ * @return array data without useless information
+ *
+ * @throws RestException
+ */
+ public function getContacts($id, $type = '')
+ {
+ if (! DolibarrApiAccess::$user->rights->commande->lire) {
+ throw new RestException(401);
+ }
- $result = $this->commande->fetch($id);
- if ( ! $result ) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if ( ! $result ) {
+ throw new RestException(404, 'Order not found');
+ }
- if ( ! DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ if ( ! DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
- $contacts = $this->commande->liste_contact(-1, 'external', 0, $type);
+ $contacts = $this->commande->liste_contact(-1, 'external', 0, $type);
- return $this->_cleanObjectDatas($contacts);
- }
+ return $this->_cleanObjectDatas($contacts);
+ }
- /**
+ /**
* Add a contact type of given order
*
* @param int $id Id of order to update
@@ -504,43 +504,43 @@ class Orders extends DolibarrApi
*
* @return int
*
- * @throws RestException 401
- * @throws RestException 404
+ * @throws RestException 401
+ * @throws RestException 404
*/
- public function postContact($id, $contactid, $type)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ public function postContact($id, $contactid, $type)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
- $result = $this->commande->add_contact($contactid, $type, 'external');
+ $result = $this->commande->add_contact($contactid, $type, 'external');
- if ($result < 0) {
- throw new RestException(500, 'Error when added the contact');
- }
+ if ($result < 0) {
+ throw new RestException(500, 'Error when added the contact');
+ }
- if ($result == 0) {
- throw new RestException(304, 'contact already added');
- }
+ if ($result == 0) {
+ throw new RestException(304, 'contact already added');
+ }
- return array(
- 'success' => array(
- 'code' => 200,
- 'message' => 'Contact linked to the order'
- )
- );
- }
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'Contact linked to the order'
+ )
+ );
+ }
- /**
+ /**
* Unlink a contact type of given order
*
* @param int $id Id of order to update
@@ -550,143 +550,143 @@ class Orders extends DolibarrApi
*
* @return int
*
- * @throws RestException 401
- * @throws RestException 404
- * @throws RestException 500
+ * @throws RestException 401
+ * @throws RestException 404
+ * @throws RestException 500
*/
- public function deleteContact($id, $rowid)
- {
- if (! DolibarrApiAccess::$user->rights->commande->creer) {
+ public function deleteContact($id, $rowid)
+ {
+ if (! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (! $result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (! $result) {
+ throw new RestException(404, 'Order not found');
+ }
if (! DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
- $result = $this->commande->delete_linked_contact($rowid);
+ $result = $this->commande->delete_linked_contact($rowid);
- if (!$result) {
- throw new RestException(500, 'Error when deleted the contact');
- }
+ if (!$result) {
+ throw new RestException(500, 'Error when deleted the contact');
+ }
- return array(
- 'success' => array(
- 'code' => 200,
- 'message' => 'Contact unlinked from order'
- )
- );
- }
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'Contact unlinked from order'
+ )
+ );
+ }
- /**
- * Update order general fields (won't touch lines of order)
- *
- * @param int $id Id of order to update
- * @param array $request_data Datas
- *
- * @return int
- */
- public function put($id, $request_data = null)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ /**
+ * Update order general fields (won't touch lines of order)
+ *
+ * @param int $id Id of order to update
+ * @param array $request_data Datas
+ *
+ * @return int
+ */
+ public function put($id, $request_data = null)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
- foreach ($request_data as $field => $value) {
- if ($field == 'id') continue;
- $this->commande->$field = $value;
- }
+ foreach ($request_data as $field => $value) {
+ if ($field == 'id') continue;
+ $this->commande->$field = $value;
+ }
// Update availability
if (!empty($this->commande->availability_id)) {
- if ($this->commande->availability($this->commande->availability_id) < 0)
+ if ($this->commande->availability($this->commande->availability_id) < 0)
throw new RestException(400, 'Error while updating availability');
}
- if ($this->commande->update(DolibarrApiAccess::$user) > 0)
- {
- return $this->get($id);
- } else {
- throw new RestException(500, $this->commande->error);
- }
- }
+ if ($this->commande->update(DolibarrApiAccess::$user) > 0)
+ {
+ return $this->get($id);
+ } else {
+ throw new RestException(500, $this->commande->error);
+ }
+ }
- /**
- * Delete order
- *
- * @param int $id Order ID
- * @return array
- */
- public function delete($id)
- {
- if (!DolibarrApiAccess::$user->rights->commande->supprimer) {
+ /**
+ * Delete order
+ *
+ * @param int $id Order ID
+ * @return array
+ */
+ public function delete($id)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->supprimer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
- if (!$this->commande->delete(DolibarrApiAccess::$user)) {
- throw new RestException(500, 'Error when deleting order : '.$this->commande->error);
- }
+ if (!$this->commande->delete(DolibarrApiAccess::$user)) {
+ throw new RestException(500, 'Error when deleting order : '.$this->commande->error);
+ }
- return array(
- 'success' => array(
- 'code' => 200,
- 'message' => 'Order deleted'
- )
- );
- }
+ return array(
+ 'success' => array(
+ 'code' => 200,
+ 'message' => 'Order deleted'
+ )
+ );
+ }
- /**
- * Validate an order
- *
+ /**
+ * Validate an order
+ *
* If you get a bad value for param notrigger check, provide this in body
- * {
- * "idwarehouse": 0,
- * "notrigger": 0
- * }
- *
- * @param int $id Order ID
- * @param int $idwarehouse Warehouse ID
- * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
- *
- * @url POST {id}/validate
- *
+ * {
+ * "idwarehouse": 0,
+ * "notrigger": 0
+ * }
+ *
+ * @param int $id Order ID
+ * @param int $idwarehouse Warehouse ID
+ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
+ *
+ * @url POST {id}/validate
+ *
* @throws RestException 304
- * @throws RestException 401
- * @throws RestException 404
- * @throws RestException 500
- *
- * @return array
- */
- public function validate($id, $idwarehouse = 0, $notrigger = 0)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ * @throws RestException 401
+ * @throws RestException 404
+ * @throws RestException 500
+ *
+ * @return array
+ */
+ public function validate($id, $idwarehouse = 0, $notrigger = 0)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401);
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
@@ -694,288 +694,288 @@ class Orders extends DolibarrApi
$result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
if ($result == 0) {
- throw new RestException(304, 'Error nothing done. May be object is already validated');
+ throw new RestException(304, 'Error nothing done. May be object is already validated');
}
if ($result < 0) {
- throw new RestException(500, 'Error when validating Order: '.$this->commande->error);
+ throw new RestException(500, 'Error when validating Order: '.$this->commande->error);
+ }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
}
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
- $this->commande->fetchObjectLinked();
+ $this->commande->fetchObjectLinked();
- return $this->_cleanObjectDatas($this->commande);
- }
+ return $this->_cleanObjectDatas($this->commande);
+ }
- /**
- * Tag the order as validated (opened)
- *
- * Function used when order is reopend after being closed.
- *
- * @param int $id Id of the order
- *
- * @url POST {id}/reopen
- *
- * @return int
- *
- * @throws RestException 304
- * @throws RestException 400
- * @throws RestException 401
- * @throws RestException 404
- * @throws RestException 405
- */
- public function reopen($id)
- {
+ /**
+ * Tag the order as validated (opened)
+ *
+ * Function used when order is reopend after being closed.
+ *
+ * @param int $id Id of the order
+ *
+ * @url POST {id}/reopen
+ *
+ * @return int
+ *
+ * @throws RestException 304
+ * @throws RestException 400
+ * @throws RestException 401
+ * @throws RestException 404
+ * @throws RestException 405
+ */
+ public function reopen($id)
+ {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
- throw new RestException(401);
- }
- if (empty($id)) {
- throw new RestException(400, 'Order ID is mandatory');
- }
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ throw new RestException(401);
+ }
+ if (empty($id)) {
+ throw new RestException(400, 'Order ID is mandatory');
+ }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
- $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
- if ($result < 0) {
- throw new RestException(405, $this->commande->error);
- } elseif ($result == 0) {
- throw new RestException(304);
- }
+ $result = $this->commande->set_reopen(DolibarrApiAccess::$user);
+ if ($result < 0) {
+ throw new RestException(405, $this->commande->error);
+ } elseif ($result == 0) {
+ throw new RestException(304);
+ }
- return $result;
- }
+ return $result;
+ }
- /**
- * Classify the order as invoiced. Could be also called setbilled
- *
- * @param int $id Id of the order
- *
- * @url POST {id}/setinvoiced
- *
- * @return int
- *
- * @throws RestException 400
- * @throws RestException 401
- * @throws RestException 404
- * @throws RestException 405
- */
- public function setinvoiced($id)
- {
+ /**
+ * Classify the order as invoiced. Could be also called setbilled
+ *
+ * @param int $id Id of the order
+ *
+ * @url POST {id}/setinvoiced
+ *
+ * @return int
+ *
+ * @throws RestException 400
+ * @throws RestException 401
+ * @throws RestException 404
+ * @throws RestException 405
+ */
+ public function setinvoiced($id)
+ {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
- throw new RestException(401);
- }
- if (empty($id)) {
- throw new RestException(400, 'Order ID is mandatory');
- }
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ throw new RestException(401);
+ }
+ if (empty($id)) {
+ throw new RestException(400, 'Order ID is mandatory');
+ }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
- $result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
- if ($result < 0) {
- throw new RestException(400, $this->commande->error);
- }
-
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
-
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
-
- $this->commande->fetchObjectLinked();
-
- return $this->_cleanObjectDatas($this->commande);
- }
-
- /**
- * Close an order (Classify it as "Delivered")
- *
- * @param int $id Order ID
- * @param int $notrigger Disabled triggers
- *
- * @url POST {id}/close
- *
- * @return int
- */
- public function close($id, $notrigger = 0)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
- throw new RestException(401);
- }
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
-
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
-
- $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
- if ($result == 0) {
- throw new RestException(304, 'Error nothing done. May be object is already closed');
- }
- if ($result < 0) {
- throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
- }
-
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
-
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
-
- $this->commande->fetchObjectLinked();
-
- return $this->_cleanObjectDatas($this->commande);
- }
-
- /**
- * Set an order to draft
- *
- * @param int $id Order ID
- * @param int $idwarehouse Warehouse ID to use for stock change (Used only if option STOCK_CALCULATE_ON_VALIDATE_ORDER is on)
- *
- * @url POST {id}/settodraft
- *
- * @return array
- */
- public function settodraft($id, $idwarehouse = -1)
- {
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
- throw new RestException(401);
- }
- $result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
-
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
-
- $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
- if ($result == 0) {
- throw new RestException(304, 'Nothing done. May be object is already closed');
- }
- if ($result < 0) {
- throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
- }
+ $result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
+ if ($result < 0) {
+ throw new RestException(400, $this->commande->error);
+ }
$result = $this->commande->fetch($id);
- if (!$result) {
- throw new RestException(404, 'Order not found');
- }
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
- if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
- throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
- }
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
- $this->commande->fetchObjectLinked();
+ $this->commande->fetchObjectLinked();
- return $this->_cleanObjectDatas($this->commande);
- }
+ return $this->_cleanObjectDatas($this->commande);
+ }
+
+ /**
+ * Close an order (Classify it as "Delivered")
+ *
+ * @param int $id Order ID
+ * @param int $notrigger Disabled triggers
+ *
+ * @url POST {id}/close
+ *
+ * @return int
+ */
+ public function close($id, $notrigger = 0)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ throw new RestException(401);
+ }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $result = $this->commande->cloture(DolibarrApiAccess::$user, $notrigger);
+ if ($result == 0) {
+ throw new RestException(304, 'Error nothing done. May be object is already closed');
+ }
+ if ($result < 0) {
+ throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
+ }
+
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $this->commande->fetchObjectLinked();
+
+ return $this->_cleanObjectDatas($this->commande);
+ }
+
+ /**
+ * Set an order to draft
+ *
+ * @param int $id Order ID
+ * @param int $idwarehouse Warehouse ID to use for stock change (Used only if option STOCK_CALCULATE_ON_VALIDATE_ORDER is on)
+ *
+ * @url POST {id}/settodraft
+ *
+ * @return array
+ */
+ public function settodraft($id, $idwarehouse = -1)
+ {
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ throw new RestException(401);
+ }
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $result = $this->commande->setDraft(DolibarrApiAccess::$user, $idwarehouse);
+ if ($result == 0) {
+ throw new RestException(304, 'Nothing done. May be object is already closed');
+ }
+ if ($result < 0) {
+ throw new RestException(500, 'Error when closing Order: '.$this->commande->error);
+ }
+
+ $result = $this->commande->fetch($id);
+ if (!$result) {
+ throw new RestException(404, 'Order not found');
+ }
+
+ if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
+ throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
+ }
+
+ $this->commande->fetchObjectLinked();
+
+ return $this->_cleanObjectDatas($this->commande);
+ }
- /**
- * Create an order using an existing proposal.
- *
- *
- * @param int $proposalid Id of the proposal
- *
- * @url POST /createfromproposal/{proposalid}
- *
- * @return int
- * @throws RestException 400
- * @throws RestException 401
- * @throws RestException 404
- * @throws RestException 405
- */
- public function createOrderFromProposal($proposalid)
- {
+ /**
+ * Create an order using an existing proposal.
+ *
+ *
+ * @param int $proposalid Id of the proposal
+ *
+ * @url POST /createfromproposal/{proposalid}
+ *
+ * @return int
+ * @throws RestException 400
+ * @throws RestException 401
+ * @throws RestException 404
+ * @throws RestException 405
+ */
+ public function createOrderFromProposal($proposalid)
+ {
- require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
+ require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
- if (!DolibarrApiAccess::$user->rights->propal->lire) {
- throw new RestException(401);
- }
- if (!DolibarrApiAccess::$user->rights->commande->creer) {
- throw new RestException(401);
- }
- if (empty($proposalid)) {
- throw new RestException(400, 'Proposal ID is mandatory');
- }
+ if (!DolibarrApiAccess::$user->rights->propal->lire) {
+ throw new RestException(401);
+ }
+ if (!DolibarrApiAccess::$user->rights->commande->creer) {
+ throw new RestException(401);
+ }
+ if (empty($proposalid)) {
+ throw new RestException(400, 'Proposal ID is mandatory');
+ }
- $propal = new Propal($this->db);
- $result = $propal->fetch($proposalid);
- if (!$result) {
- throw new RestException(404, 'Proposal not found');
- }
+ $propal = new Propal($this->db);
+ $result = $propal->fetch($proposalid);
+ if (!$result) {
+ throw new RestException(404, 'Proposal not found');
+ }
- $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
- if ($result < 0) {
- throw new RestException(405, $this->commande->error);
- }
- $this->commande->fetchObjectLinked();
+ $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user);
+ if ($result < 0) {
+ throw new RestException(405, $this->commande->error);
+ }
+ $this->commande->fetchObjectLinked();
- return $this->_cleanObjectDatas($this->commande);
- }
+ return $this->_cleanObjectDatas($this->commande);
+ }
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
- /**
- * Clean sensible object datas
- *
- * @param object $object Object to clean
- * @return array Array of cleaned object properties
- */
- protected function _cleanObjectDatas($object)
- {
- // phpcs:enable
- $object = parent::_cleanObjectDatas($object);
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
+ /**
+ * Clean sensible object datas
+ *
+ * @param object $object Object to clean
+ * @return array Array of cleaned object properties
+ */
+ protected function _cleanObjectDatas($object)
+ {
+ // phpcs:enable
+ $object = parent::_cleanObjectDatas($object);
- unset($object->note);
- unset($object->address);
- unset($object->barcode_type);
- unset($object->barcode_type_code);
- unset($object->barcode_type_label);
- unset($object->barcode_type_coder);
+ unset($object->note);
+ unset($object->address);
+ unset($object->barcode_type);
+ unset($object->barcode_type_code);
+ unset($object->barcode_type_label);
+ unset($object->barcode_type_coder);
- return $object;
- }
+ return $object;
+ }
- /**
- * Validate fields before create or update object
- *
- * @param array $data Array with data to verify
- * @return array
- * @throws RestException
- */
- private function _validate($data)
- {
- $commande = array();
- foreach (Orders::$FIELDS as $field) {
- if (!isset($data[$field]))
- throw new RestException(400, $field." field missing");
- $commande[$field] = $data[$field];
- }
- return $commande;
- }
+ /**
+ * Validate fields before create or update object
+ *
+ * @param array $data Array with data to verify
+ * @return array
+ * @throws RestException
+ */
+ private function _validate($data)
+ {
+ $commande = array();
+ foreach (Orders::$FIELDS as $field) {
+ if (!isset($data[$field]))
+ throw new RestException(400, $field." field missing");
+ $commande[$field] = $data[$field];
+ }
+ return $commande;
+ }
}
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 73dd2cee9fb..7119e85b473 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -99,13 +99,13 @@ class Commande extends CommonOrder
*/
public $ref_client;
- /**
+ /**
* @var string Internal ref for order
* @deprecated
*/
public $ref_int;
- /**
+ /**
* @var int Contact ID
*/
public $contactid;
@@ -121,15 +121,15 @@ class Commande extends CommonOrder
*/
public $billed;
- /**
- * @var int Draft Status of the order
- */
- public $brouillon;
- public $cond_reglement_code;
+ /**
+ * @var int Draft Status of the order
+ */
+ public $brouillon;
+ public $cond_reglement_code;
/**
- * @var int bank account ID
- */
+ * @var int bank account ID
+ */
public $fk_account;
/**
@@ -168,12 +168,12 @@ class Commande extends CommonOrder
public $demand_reason_id; // Source reason. Why we receive order (after a phone campaign, ...)
public $demand_reason_code;
/**
- * @var int Date of order
+ * @var int Date of order
*/
public $date;
/**
- * @var int Date of order
+ * @var int Date of order
* @deprecated
* @see $date
*/
@@ -182,8 +182,8 @@ class Commande extends CommonOrder
public $date_livraison; // Date expected of shipment (date starting shipment, not the reception that occurs some days after)
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_remise_except;
public $remise_percent;
@@ -197,13 +197,13 @@ class Commande extends CommonOrder
public $linked_objects = array();
/**
- * @var int User author ID
- */
+ * @var int User author ID
+ */
public $user_author_id;
- /**
- * @var int User validator ID
- */
+ /**
+ * @var int User validator ID
+ */
public $user_valid;
/**
@@ -213,8 +213,8 @@ class Commande extends CommonOrder
// Multicurrency
/**
- * @var int Currency ID
- */
+ * @var int Currency ID
+ */
public $fk_multicurrency;
public $multicurrency_code;
@@ -223,9 +223,9 @@ class Commande extends CommonOrder
public $multicurrency_total_tva;
public $multicurrency_total_ttc;
- /**
- * @var Commande clone of order object
- */
+ /**
+ * @var Commande clone of order object
+ */
public $oldcopy;
//! key of module source when order generated from a dedicated module ('cashdesk', 'takepos', ...)
@@ -394,11 +394,11 @@ class Commande extends CommonOrder
$mybool |= @include_once $dir.$file;
}
- if ($mybool === false)
- {
- dol_print_error('', "Failed to include file ".$file);
- return '';
- }
+ if ($mybool === false)
+ {
+ dol_print_error('', "Failed to include file ".$file);
+ return '';
+ }
$obj = new $classname();
$numref = $obj->getNextValue($soc, $this);
@@ -568,7 +568,7 @@ class Commande extends CommonOrder
{
$this->ref = $num;
$this->statut = self::STATUS_VALIDATED;
- $this->brouillon = 0;
+ $this->brouillon = 0;
}
if (!$error)
@@ -589,9 +589,9 @@ class Commande extends CommonOrder
* @param int $idwarehouse Warehouse ID to use for stock change (Used only if option STOCK_CALCULATE_ON_VALIDATE_ORDER is on)
* @return int <0 if KO, >0 if OK
*/
- public function setDraft($user, $idwarehouse = -1)
- {
- //phpcs:enable
+ public function setDraft($user, $idwarehouse = -1)
+ {
+ //phpcs:enable
global $conf, $langs;
$error = 0;
@@ -619,12 +619,12 @@ class Commande extends CommonOrder
if ($this->db->query($sql))
{
- if (!$error)
- {
- $this->oldcopy = clone $this;
- }
+ if (!$error)
+ {
+ $this->oldcopy = clone $this;
+ }
- // If stock is decremented on validate order, we must reincrement it
+ // If stock is decremented on validate order, we must reincrement it
if (!empty($conf->stock->enabled) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
{
$result = 0;
@@ -665,7 +665,7 @@ class Commande extends CommonOrder
$this->db->rollback();
return -1;
}
- }
+ }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -678,7 +678,7 @@ class Commande extends CommonOrder
*/
public function set_reopen($user)
{
- // phpcs:enable
+ // phpcs:enable
$error = 0;
if ($this->statut != self::STATUS_CANCELED && $this->statut != self::STATUS_CLOSED)
@@ -958,7 +958,7 @@ class Commande extends CommonOrder
$sql .= ", ".(int) $this->fk_incoterms;
$sql .= ", '".$this->db->escape($this->location_incoterms)."'";
$sql .= ", ".setEntity($this);
- $sql .= ", ".($this->module_source ? "'".$this->db->escape($this->module_source)."'" : "null");
+ $sql .= ", ".($this->module_source ? "'".$this->db->escape($this->module_source)."'" : "null");
$sql .= ", ".($this->pos_source != '' ? "'".$this->db->escape($this->pos_source)."'" : "null");
$sql .= ", ".(int) $this->fk_multicurrency;
$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
@@ -1009,7 +1009,7 @@ class Commande extends CommonOrder
$line->ref_ext = '';
}
- $result = $this->addline(
+ $result = $this->addline(
$line->desc,
$line->subprice,
$line->qty,
@@ -1033,10 +1033,10 @@ class Commande extends CommonOrder
$line->label,
$line->array_options,
$line->fk_unit,
- $origintype,
- $originid,
+ $origintype,
+ $originid,
0,
- $line->ref_ext
+ $line->ref_ext
);
if ($result < 0)
{
@@ -1357,8 +1357,8 @@ class Commande extends CommonOrder
if (empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN))
{
- $this->note_private = $object->note_private;
- $this->note_public = $object->note_public;
+ $this->note_private = $object->note_private;
+ $this->note_public = $object->note_public;
}
$this->origin = $object->element;
@@ -1502,7 +1502,7 @@ class Commande extends CommonOrder
return -1;
}
- $this->db->begin();
+ $this->db->begin();
$product_type = $type;
if (!empty($fk_product))
@@ -1681,7 +1681,7 @@ class Commande extends CommonOrder
*/
public function add_product($idproduct, $qty, $remise_percent = 0.0, $date_start = '', $date_end = '')
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $mysoc;
if (!$qty) $qty = 1;
@@ -1780,7 +1780,7 @@ class Commande extends CommonOrder
$sql .= ', c.fk_incoterms, c.location_incoterms';
$sql .= ", c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc";
$sql .= ", c.module_source, c.pos_source";
- $sql .= ", i.libelle as label_incoterms";
+ $sql .= ", i.libelle as label_incoterms";
$sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql .= ', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc';
$sql .= ', ca.code as availability_code, ca.label as availability_label';
@@ -1917,7 +1917,7 @@ class Commande extends CommonOrder
*/
public function insert_discount($idremise)
{
- // phpcs:enable
+ // phpcs:enable
global $langs;
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@@ -1992,7 +1992,7 @@ class Commande extends CommonOrder
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
{
global $langs, $conf;
- // phpcs:enable
+ // phpcs:enable
$this->lines = array();
$sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.vat_src_code, l.tva_tx, l.ref_ext,';
@@ -2086,13 +2086,13 @@ class Commande extends CommonOrder
$line->fetch_optionals();
// multilangs
- if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
- $line = new Product($this->db);
- $line->fetch($objp->fk_product);
- $line->getMultiLangs();
- }
+ if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
+ $line = new Product($this->db);
+ $line->fetch($objp->fk_product);
+ $line->getMultiLangs();
+ }
- $this->lines[$i] = $line;
+ $this->lines[$i] = $line;
$i++;
}
@@ -2224,7 +2224,7 @@ class Commande extends CommonOrder
*/
public function nb_expedition()
{
- // phpcs:enable
+ // phpcs:enable
$sql = 'SELECT count(*)';
$sql .= ' FROM '.MAIN_DB_PREFIX.'expedition as e';
$sql .= ', '.MAIN_DB_PREFIX.'element_element as el';
@@ -2251,7 +2251,7 @@ class Commande extends CommonOrder
*/
public function stock_array($filtre_statut = self::STATUS_CANCELED)
{
- // phpcs:enable
+ // phpcs:enable
$this->stocks = array();
// Tableau des id de produit de la commande
@@ -2359,7 +2359,7 @@ class Commande extends CommonOrder
*/
public function set_remise($user, $remise, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
$remise = trim($remise) ?trim($remise) : 0;
if ($user->rights->commande->creer)
@@ -2425,7 +2425,7 @@ class Commande extends CommonOrder
*/
public function set_remise_absolue($user, $remise, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
$remise = trim($remise) ?trim($remise) : 0;
if ($user->rights->commande->creer)
@@ -2491,7 +2491,7 @@ class Commande extends CommonOrder
*/
public function set_date($user, $date, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
if ($user->rights->commande->creer)
{
$error = 0;
@@ -2553,7 +2553,7 @@ class Commande extends CommonOrder
*/
public function set_date_livraison($user, $date_livraison, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
if ($user->rights->commande->creer)
{
$error = 0;
@@ -2620,7 +2620,7 @@ class Commande extends CommonOrder
*/
public function liste_array($shortlist = 0, $draft = 0, $excluser = '', $socid = 0, $limit = 0, $offset = 0, $sortfield = 'c.date_commande', $sortorder = 'DESC')
{
- // phpcs:enable
+ // phpcs:enable
global $user;
$ga = array();
@@ -2750,7 +2750,7 @@ class Commande extends CommonOrder
*/
public function demand_reason($demand_reason_id, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
global $user;
dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
@@ -2819,7 +2819,7 @@ class Commande extends CommonOrder
*/
public function set_ref_client($user, $ref_client, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
if ($user->rights->commande->creer)
{
$error = 0;
@@ -3321,9 +3321,9 @@ class Commande extends CommonOrder
if (!$error)
{
// Delete extrafields of order details
- $main = MAIN_DB_PREFIX.'commandedet';
- $ef = $main."_extrafields";
- $sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.")";
+ $main = MAIN_DB_PREFIX.'commandedet';
+ $ef = $main."_extrafields";
+ $sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.")";
if (!$this->db->query($sql))
{
$error++;
@@ -3432,7 +3432,7 @@ class Commande extends CommonOrder
*/
public function load_board($user)
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $langs;
$clause = " WHERE";
@@ -3521,45 +3521,45 @@ class Commande extends CommonOrder
*/
public function LibStatut($status, $billed, $mode, $donotshowbilled = 0)
{
- // phpcs:enable
+ // phpcs:enable
global $langs, $conf;
$billedtext = '';
if (empty($donotshowbilled)) $billedtext .= ($billed ? ' - '.$langs->trans("Billed") : '');
if ($status == self::STATUS_CANCELED) {
- $labelStatus = $langs->trans('StatusOrderCanceled');
- $labelStatusShort = $langs->trans('StatusOrderCanceledShort');
- $statusType = 'status9';
+ $labelStatus = $langs->trans('StatusOrderCanceled');
+ $labelStatusShort = $langs->trans('StatusOrderCanceledShort');
+ $statusType = 'status9';
} elseif ($status == self::STATUS_DRAFT) {
- $labelStatus = $langs->trans('StatusOrderDraft');
- $labelStatusShort = $langs->trans('StatusOrderDraftShort');
- $statusType = 'status0';
+ $labelStatus = $langs->trans('StatusOrderDraft');
+ $labelStatusShort = $langs->trans('StatusOrderDraftShort');
+ $statusType = 'status0';
} elseif ($status == self::STATUS_VALIDATED) {
- $labelStatus = $langs->trans('StatusOrderValidated').$billedtext;
- $labelStatusShort = $langs->trans('StatusOrderValidatedShort').$billedtext;
- $statusType = 'status1';
+ $labelStatus = $langs->trans('StatusOrderValidated').$billedtext;
+ $labelStatusShort = $langs->trans('StatusOrderValidatedShort').$billedtext;
+ $statusType = 'status1';
} elseif ($status == self::STATUS_SHIPMENTONPROCESS) {
- $labelStatus = $langs->trans('StatusOrderSentShort').$billedtext;
- $labelStatusShort = $langs->trans('StatusOrderSentShort').$billedtext;
- $statusType = 'status4';
+ $labelStatus = $langs->trans('StatusOrderSentShort').$billedtext;
+ $labelStatusShort = $langs->trans('StatusOrderSentShort').$billedtext;
+ $statusType = 'status4';
} elseif ($status == self::STATUS_CLOSED && (!$billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) {
- $labelStatus = $langs->trans('StatusOrderToBill');
- $labelStatusShort = $langs->trans('StatusOrderToBillShort');
- $statusType = 'status4';
+ $labelStatus = $langs->trans('StatusOrderToBill');
+ $labelStatusShort = $langs->trans('StatusOrderToBillShort');
+ $statusType = 'status4';
} elseif ($status == self::STATUS_CLOSED && ($billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) {
- $labelStatus = $langs->trans('StatusOrderProcessed').$billedtext;
- $labelStatusShort = $langs->trans('StatusOrderProcessed').$billedtext;
- $statusType = 'status6';
+ $labelStatus = $langs->trans('StatusOrderProcessed').$billedtext;
+ $labelStatusShort = $langs->trans('StatusOrderProcessed').$billedtext;
+ $statusType = 'status6';
} elseif ($status == self::STATUS_CLOSED && (!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) {
- $labelStatus = $langs->trans('StatusOrderDelivered');
- $labelStatusShort = $langs->trans('StatusOrderDelivered');
- $statusType = 'status6';
+ $labelStatus = $langs->trans('StatusOrderDelivered');
+ $labelStatusShort = $langs->trans('StatusOrderDelivered');
+ $statusType = 'status6';
} else {
- $labelStatus = $langs->trans('Unknown');
- $labelStatusShort = '';
- $statusType = '';
- $mode = 0;
+ $labelStatus = $langs->trans('Unknown');
+ $labelStatusShort = '';
+ $statusType = '';
+ $mode = 0;
}
return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
@@ -3825,7 +3825,7 @@ class Commande extends CommonOrder
*/
public function load_state_board()
{
- // phpcs:enable
+ // phpcs:enable
global $user;
$this->nb = array();
@@ -4024,10 +4024,10 @@ class OrderLine extends CommonOrderLine
*
* @param DoliDB $db handler d'acces base de donnee
*/
- public function __construct($db)
- {
- $this->db = $db;
- }
+ public function __construct($db)
+ {
+ $this->db = $db;
+ }
/**
* Load line order
@@ -4125,32 +4125,32 @@ class OrderLine extends CommonOrderLine
$error = 0;
- // check if order line is not in a shipment line before deleting
- $sqlCheckShipmentLine = "SELECT";
- $sqlCheckShipmentLine .= " ed.rowid";
- $sqlCheckShipmentLine .= " FROM ".MAIN_DB_PREFIX."expeditiondet ed";
- $sqlCheckShipmentLine .= " WHERE ed.fk_origin_line = ".$this->rowid;
+ // check if order line is not in a shipment line before deleting
+ $sqlCheckShipmentLine = "SELECT";
+ $sqlCheckShipmentLine .= " ed.rowid";
+ $sqlCheckShipmentLine .= " FROM ".MAIN_DB_PREFIX."expeditiondet ed";
+ $sqlCheckShipmentLine .= " WHERE ed.fk_origin_line = ".$this->rowid;
- $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine);
- if (!$resqlCheckShipmentLine) {
- $error++;
- $this->error = $this->db->lasterror();
- $this->errors[] = $this->error;
- } else {
- $langs->load('errors');
- $num = $this->db->num_rows($resqlCheckShipmentLine);
- if ($num > 0) {
- $error++;
- $objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine);
- $this->error = $langs->trans('ErrorRecordAlreadyExists').' : '.$langs->trans('ShipmentLine').' '.$objCheckShipmentLine->rowid;
- $this->errors[] = $this->error;
- }
- $this->db->free($resqlCheckShipmentLine);
- }
- if ($error) {
- dol_syslog(__METHOD__.'Error ; '.$this->error, LOG_ERR);
- return -1;
- }
+ $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine);
+ if (!$resqlCheckShipmentLine) {
+ $error++;
+ $this->error = $this->db->lasterror();
+ $this->errors[] = $this->error;
+ } else {
+ $langs->load('errors');
+ $num = $this->db->num_rows($resqlCheckShipmentLine);
+ if ($num > 0) {
+ $error++;
+ $objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine);
+ $this->error = $langs->trans('ErrorRecordAlreadyExists').' : '.$langs->trans('ShipmentLine').' '.$objCheckShipmentLine->rowid;
+ $this->errors[] = $this->error;
+ }
+ $this->db->free($resqlCheckShipmentLine);
+ }
+ if ($error) {
+ dol_syslog(__METHOD__.'Error ; '.$this->error, LOG_ERR);
+ return -1;
+ }
$this->db->begin();
@@ -4482,7 +4482,7 @@ class OrderLine extends CommonOrderLine
*/
public function update_total()
{
- // phpcs:enable
+ // phpcs:enable
$this->db->begin();
// Clean parameters
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 20f705a8ed9..9db3c8fcd96 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -100,13 +100,13 @@ class Facture extends CommonInvoice
public $author;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_author;
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_user_valid;
public $date; // Date invoice
@@ -153,8 +153,8 @@ class Facture extends CommonInvoice
public $mode_reglement_code; // Code in llx_c_paiement
/**
- * @var int ID Field to store bank id to use when payment mode is withdraw
- */
+ * @var int ID Field to store bank id to use when payment mode is withdraw
+ */
public $fk_bank;
/**
@@ -175,8 +175,8 @@ class Facture extends CommonInvoice
// Multicurrency
/**
- * @var int ID
- */
+ * @var int ID
+ */
public $fk_multicurrency;
public $multicurrency_code;
@@ -323,30 +323,30 @@ class Facture extends CommonInvoice
);
// END MODULEBUILDER PROPERTIES
- /**
- * Standard invoice
- */
- const TYPE_STANDARD = 0;
+ /**
+ * Standard invoice
+ */
+ const TYPE_STANDARD = 0;
- /**
- * Replacement invoice
- */
- const TYPE_REPLACEMENT = 1;
+ /**
+ * Replacement invoice
+ */
+ const TYPE_REPLACEMENT = 1;
- /**
- * Credit note invoice
- */
- const TYPE_CREDIT_NOTE = 2;
+ /**
+ * Credit note invoice
+ */
+ const TYPE_CREDIT_NOTE = 2;
- /**
- * Deposit invoice
- */
- const TYPE_DEPOSIT = 3;
+ /**
+ * Deposit invoice
+ */
+ const TYPE_DEPOSIT = 3;
- /**
- * Proforma invoice (should not be used. a proforma is an order)
- */
- const TYPE_PROFORMA = 4;
+ /**
+ * Proforma invoice (should not be used. a proforma is an order)
+ */
+ const TYPE_PROFORMA = 4;
/**
* Situation invoice
@@ -407,7 +407,7 @@ class Facture extends CommonInvoice
* @param int $forceduedate If set, do not recalculate due date from payment condition but force it with value
* @return int <0 if KO, >0 if OK
*/
- public function create(User $user, $notrigger = 0, $forceduedate = 0)
+ public function create(User $user, $notrigger = 0, $forceduedate = 0)
{
global $langs, $conf, $mysoc, $hookmanager;
$error = 0;
@@ -461,7 +461,7 @@ class Facture extends CommonInvoice
// Create invoice from a template invoice
if ($this->fac_rec > 0)
{
- $this->fk_fac_rec_source = $this->fac_rec;
+ $this->fk_fac_rec_source = $this->fac_rec;
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
$_facrec = new FactureRec($this->db);
@@ -503,9 +503,9 @@ class Facture extends CommonInvoice
$this->ref_client = trim($this->ref_client);
$this->note_public = trim($this->note_public);
$this->note_private = trim($this->note_private);
- $this->note_private = dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref));
+ $this->note_private = dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref));
- $this->array_options = $_facrec->array_options;
+ $this->array_options = $_facrec->array_options;
//if (! $this->remise) $this->remise = 0;
if (!$this->mode_reglement_id) $this->mode_reglement_id = 0;
@@ -520,12 +520,12 @@ class Facture extends CommonInvoice
// For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice
if ($_facrec->frequency > 0)
{
- dol_syslog("This is a recurring invoice so we set date_last_gen and next date_when");
- if (empty($_facrec->date_when)) $_facrec->date_when = $now;
- $next_date = $_facrec->getNextDate(); // Calculate next date
- $result = $_facrec->setValueFrom('date_last_gen', $now, '', null, 'date', '', $user, '');
- //$_facrec->setValueFrom('nb_gen_done', $_facrec->nb_gen_done + 1); // Not required, +1 already included into setNextDate when second param is 1.
- $result = $_facrec->setNextDate($next_date, 1);
+ dol_syslog("This is a recurring invoice so we set date_last_gen and next date_when");
+ if (empty($_facrec->date_when)) $_facrec->date_when = $now;
+ $next_date = $_facrec->getNextDate(); // Calculate next date
+ $result = $_facrec->setValueFrom('date_last_gen', $now, '', null, 'date', '', $user, '');
+ //$_facrec->setValueFrom('nb_gen_done', $_facrec->nb_gen_done + 1); // Not required, +1 already included into setNextDate when second param is 1.
+ $result = $_facrec->setNextDate($next_date, 1);
}
// Define lang of customer
@@ -536,8 +536,8 @@ class Facture extends CommonInvoice
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->default_lang)) $newlang = $this->default_lang; // for thirdparty
if (!empty($newlang))
{
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
}
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
@@ -567,16 +567,16 @@ class Facture extends CommonInvoice
}
// Define due date if not already defined
- if (empty($forceduedate)) {
- $duedate = $this->calculate_date_lim_reglement();
- /*if ($duedate < 0) { Regression, a date can be negative if before 1970.
+ if (empty($forceduedate)) {
+ $duedate = $this->calculate_date_lim_reglement();
+ /*if ($duedate < 0) { Regression, a date can be negative if before 1970.
dol_syslog(__METHOD__ . ' Error in calculate_date_lim_reglement. We got ' . $duedate, LOG_ERR);
return -1;
}*/
- $this->date_lim_reglement = $duedate;
- } else {
- $this->date_lim_reglement = $forceduedate;
- }
+ $this->date_lim_reglement = $duedate;
+ } else {
+ $this->date_lim_reglement = $forceduedate;
+ }
// Insert into database
$socid = $this->socid;
@@ -595,17 +595,17 @@ class Facture extends CommonInvoice
$sql .= ", note_private";
$sql .= ", note_public";
$sql .= ", ref_client, ref_int";
- $sql .= ", fk_account";
+ $sql .= ", fk_account";
$sql .= ", module_source, pos_source, fk_fac_rec_source, fk_facture_source, fk_user_author, fk_projet";
$sql .= ", fk_cond_reglement, fk_mode_reglement, date_lim_reglement, model_pdf";
$sql .= ", situation_cycle_ref, situation_counter, situation_final";
$sql .= ", fk_incoterms, location_incoterms";
- $sql .= ", fk_multicurrency";
- $sql .= ", multicurrency_code";
- $sql .= ", multicurrency_tx";
- $sql .= ", retained_warranty";
- $sql .= ", retained_warranty_date_limit";
- $sql .= ", retained_warranty_fk_cond_reglement";
+ $sql .= ", fk_multicurrency";
+ $sql .= ", multicurrency_code";
+ $sql .= ", multicurrency_tx";
+ $sql .= ", retained_warranty";
+ $sql .= ", retained_warranty_date_limit";
+ $sql .= ", retained_warranty_fk_cond_reglement";
$sql .= ")";
$sql .= " VALUES (";
$sql .= "'(PROV)'";
@@ -636,7 +636,7 @@ class Facture extends CommonInvoice
$sql .= ", ".($this->situation_counter ? "'".$this->db->escape($this->situation_counter)."'" : "null");
$sql .= ", ".($this->situation_final ? $this->situation_final : 0);
$sql .= ", ".(int) $this->fk_incoterms;
- $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
+ $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
$sql .= ", ".(int) $this->fk_multicurrency;
$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
$sql .= ", ".(double) $this->multicurrency_tx;
@@ -667,27 +667,27 @@ class Facture extends CommonInvoice
{
foreach ($this->linked_objects as $origin => $tmp_origin_id)
{
- if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
- {
- foreach ($tmp_origin_id as $origin_id)
- {
- $ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
- $this->error = $this->db->lasterror();
- $error++;
- }
- }
- } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
- {
- $origin_id = $tmp_origin_id;
- $ret = $this->add_object_linked($origin, $origin_id);
- if (!$ret)
- {
- $this->error = $this->db->lasterror();
- $error++;
- }
- }
+ if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
+ {
+ foreach ($tmp_origin_id as $origin_id)
+ {
+ $ret = $this->add_object_linked($origin, $origin_id);
+ if (!$ret)
+ {
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+ }
+ } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
+ {
+ $origin_id = $tmp_origin_id;
+ $ret = $this->add_object_linked($origin, $origin_id);
+ if (!$ret)
+ {
+ $this->error = $this->db->lasterror();
+ $error++;
+ }
+ }
}
}
@@ -698,20 +698,20 @@ class Facture extends CommonInvoice
$originidforcontact = $this->origin_id;
if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order
{
- require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
- $exp = new Expedition($this->db);
- $exp->fetch($this->origin_id);
- $exp->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
- if (count($exp->linkedObjectsIds['commande']) > 0)
- {
- foreach ($exp->linkedObjectsIds['commande'] as $key => $value)
- {
- $originforcontact = 'commande';
- if (is_object($value)) $originidforcontact = $value->id;
- else $originidforcontact = $value;
- break; // We take first one
- }
- }
+ require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
+ $exp = new Expedition($this->db);
+ $exp->fetch($this->origin_id);
+ $exp->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
+ if (count($exp->linkedObjectsIds['commande']) > 0)
+ {
+ foreach ($exp->linkedObjectsIds['commande'] as $key => $value)
+ {
+ $originforcontact = 'commande';
+ if (is_object($value)) $originidforcontact = $value->id;
+ else $originidforcontact = $value;
+ break; // We take first one
+ }
+ }
}
$sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc";
@@ -720,11 +720,11 @@ class Facture extends CommonInvoice
$resqlcontact = $this->db->query($sqlcontact);
if ($resqlcontact)
{
- while ($objcontact = $this->db->fetch_object($resqlcontact))
- {
- //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n";
- $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object
- }
+ while ($objcontact = $this->db->fetch_object($resqlcontact))
+ {
+ //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n";
+ $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object
+ }
} else dol_print_error($resqlcontact);
}
@@ -764,12 +764,12 @@ class Facture extends CommonInvoice
$newinvoiceline->fk_parent_line = $fk_parent_line;
if ($this->type === Facture::TYPE_REPLACEMENT && $newinvoiceline->fk_remise_except) {
- $discount = new DiscountAbsolute($this->db);
- $discount->fetch($newinvoiceline->fk_remise_except);
+ $discount = new DiscountAbsolute($this->db);
+ $discount->fetch($newinvoiceline->fk_remise_except);
- $discountId = $soc->set_remise_except($discount->amount_ht, $user, $discount->description, $discount->tva_tx);
- $newinvoiceline->fk_remise_except = $discountId;
- }
+ $discountId = $soc->set_remise_except($discount->amount_ht, $user, $discount->description, $discount->tva_tx);
+ $newinvoiceline->fk_remise_except = $discountId;
+ }
$result = $newinvoiceline->insert();
@@ -793,13 +793,13 @@ class Facture extends CommonInvoice
foreach ($this->lines as $i => $val)
{
- $line = $this->lines[$i];
+ $line = $this->lines[$i];
- // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
- //if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object.
- if (!is_object($line)) $line = (object) $line;
+ // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
+ //if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object.
+ if (!is_object($line)) $line = (object) $line;
- if ($result >= 0)
+ if ($result >= 0)
{
// Reset fk_parent_line for no child products and special product
if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
@@ -823,7 +823,7 @@ class Facture extends CommonInvoice
$line->ref_ext = '';
}
- $result = $this->addline(
+ $result = $this->addline(
$line->desc,
$line->subprice,
$line->qty,
@@ -842,8 +842,8 @@ class Facture extends CommonInvoice
$line->product_type,
$line->rang,
$line->special_code,
- $origintype,
- $originid,
+ $origintype,
+ $originid,
$fk_parent_line,
$line->fk_fournprice,
$line->pa_ht,
@@ -902,26 +902,26 @@ class Facture extends CommonInvoice
$buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
// If buyprice not defined from template invoice, we try to guess the best value
if (!$buyprice && $_facrec->lines[$i]->fk_product > 0)
- {
- require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
- $producttmp = new ProductFournisseur($this->db);
- $producttmp->fetch($_facrec->lines[$i]->fk_product);
+ {
+ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
+ $producttmp = new ProductFournisseur($this->db);
+ $producttmp->fetch($_facrec->lines[$i]->fk_product);
- // If margin module defined on costprice, we try the costprice
- // If not defined or if module margin defined and pmp and stock module enabled, we try pmp price
- // else we get the best supplier price
- if ($conf->global->MARGIN_TYPE == 'costprice' && !empty($producttmp->cost_price)) $buyprice = $producttmp->cost_price;
- elseif (!empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && !empty($producttmp->pmp)) $buyprice = $producttmp->pmp;
- else {
- if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0)
- {
- if ($producttmp->product_fourn_price_id > 0)
- {
- $buyprice = price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise, 'MU');
- }
- }
- }
- }
+ // If margin module defined on costprice, we try the costprice
+ // If not defined or if module margin defined and pmp and stock module enabled, we try pmp price
+ // else we get the best supplier price
+ if ($conf->global->MARGIN_TYPE == 'costprice' && !empty($producttmp->cost_price)) $buyprice = $producttmp->cost_price;
+ elseif (!empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && !empty($producttmp->pmp)) $buyprice = $producttmp->pmp;
+ else {
+ if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0)
+ {
+ if ($producttmp->product_fourn_price_id > 0)
+ {
+ $buyprice = price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise, 'MU');
+ }
+ }
+ }
+ }
$result_insert = $this->addline(
$_facrec->lines[$i]->desc,
@@ -945,7 +945,7 @@ class Facture extends CommonInvoice
'',
0,
0,
- $fk_product_fournisseur_price,
+ $fk_product_fournisseur_price,
$buyprice,
$_facrec->lines[$i]->label,
empty($_facrec->lines[$i]->array_options) ?null:$_facrec->lines[$i]->array_options,
@@ -974,17 +974,17 @@ class Facture extends CommonInvoice
// Actions on extra fields
if (!$error)
{
- $result = $this->insertExtraFields();
- if ($result < 0) $error++;
+ $result = $this->insertExtraFields();
+ if ($result < 0) $error++;
}
- if (!$error && !$notrigger)
- {
- // Call trigger
- $result = $this->call_trigger('BILL_CREATE', $user);
- if ($result < 0) $error++;
- // End call triggers
- }
+ if (!$error && !$notrigger)
+ {
+ // Call trigger
+ $result = $this->call_trigger('BILL_CREATE', $user);
+ if ($result < 0) $error++;
+ // End call triggers
+ }
if (!$error)
{
@@ -1019,7 +1019,7 @@ class Facture extends CommonInvoice
* @param int $invertdetail Reverse sign of amounts for lines
* @return int <0 if KO, >0 if OK
*/
- public function createFromCurrent(User $user, $invertdetail = 0)
+ public function createFromCurrent(User $user, $invertdetail = 0)
{
global $conf;
@@ -1030,13 +1030,13 @@ class Facture extends CommonInvoice
// fetch optionals attributes and labels
$this->fetch_optionals();
- if (!empty($this->array_options)) {
- $facture->array_options = $this->array_options;
- }
+ if (!empty($this->array_options)) {
+ $facture->array_options = $this->array_options;
+ }
- foreach ($this->lines as &$line) {
- $line->fetch_optionals(); //fetch extrafields
- }
+ foreach ($this->lines as &$line) {
+ $line->fetch_optionals(); //fetch extrafields
+ }
$facture->fk_facture_source = $this->fk_facture_source;
$facture->type = $this->type;
@@ -1062,9 +1062,9 @@ class Facture extends CommonInvoice
$facture->situation_cycle_ref = $this->situation_cycle_ref;
$facture->situation_final = $this->situation_final;
- $facture->retained_warranty = $this->retained_warranty;
- $facture->retained_warranty_fk_cond_reglement = $this->retained_warranty_fk_cond_reglement;
- $facture->retained_warranty_date_limit = $this->retained_warranty_date_limit;
+ $facture->retained_warranty = $this->retained_warranty;
+ $facture->retained_warranty_fk_cond_reglement = $this->retained_warranty_fk_cond_reglement;
+ $facture->retained_warranty_date_limit = $this->retained_warranty_date_limit;
// Loop on each line of new invoice
@@ -1112,7 +1112,7 @@ class Facture extends CommonInvoice
/**
* Load an object from its id and create a new one in database
*
- * @param User $user User that clone
+ * @param User $user User that clone
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
@@ -1135,11 +1135,11 @@ class Facture extends CommonInvoice
if ($objsoc->fetch($this->socid) > 0)
{
- $object->socid = $objsoc->id;
- $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
- $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
- $object->fk_project = '';
- $object->fk_delivery_address = '';
+ $object->socid = $objsoc->id;
+ $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
+ $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
+ $object->fk_project = '';
+ $object->fk_delivery_address = '';
}
// TODO Change product price if multi-prices
@@ -1168,14 +1168,14 @@ class Facture extends CommonInvoice
// Loop on each line of new invoice
foreach ($object->lines as $i => $line)
{
- if (($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts
+ if (($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts
{
- unset($object->lines[$i]);
- unset($object->products[$i]); // Tant que products encore utilise
+ unset($object->lines[$i]);
+ unset($object->products[$i]); // Tant que products encore utilise
}
// Bloc to update dates of service (month by month only if previously filled at 1d near start or end of month)
// If it's a service with start and end dates
- if (!empty($line->date_start) && !empty($line->date_end) ) {
+ if (!empty($line->date_start) && !empty($line->date_end)) {
// Get the dates
$start = dol_getdate($line->date_start);
$end = dol_getdate($line->date_end);
@@ -1207,13 +1207,13 @@ class Facture extends CommonInvoice
if ($result < 0) $error++;
else {
// copy internal contacts
- if ($object->copy_linked_contact($this, 'internal') < 0)
+ if ($object->copy_linked_contact($this, 'internal') < 0)
$error++;
// copy external contacts if same company
elseif ($this->socid == $object->socid)
{
- if ($object->copy_linked_contact($this, 'external') < 0)
+ if ($object->copy_linked_contact($this, 'external') < 0)
$error++;
}
}
@@ -1250,7 +1250,7 @@ class Facture extends CommonInvoice
* @param User $user Object user
* @return int <0 if KO, 0 if nothing done, 1 if OK
*/
- public function createFromOrder($object, User $user)
+ public function createFromOrder($object, User $user)
{
global $conf, $hookmanager;
@@ -1303,7 +1303,7 @@ class Facture extends CommonInvoice
$marginInfos = getMarginInfos($object->lines[$i]->subprice, $object->lines[$i]->remise_percent, $object->lines[$i]->tva_tx, $object->lines[$i]->localtax1_tx, $object->lines[$i]->localtax2_tx, $object->lines[$i]->fk_fournprice, $object->lines[$i]->pa_ht);
$line->pa_ht = $marginInfos[0];
- // get extrafields from original line
+ // get extrafields from original line
$object->lines[$i]->fetch_optionals();
foreach ($object->lines[$i]->array_options as $options_key => $value)
$line->array_options[$options_key] = $value;
@@ -1325,17 +1325,17 @@ class Facture extends CommonInvoice
if (empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN))
{
- $this->note_private = $object->note_private;
- $this->note_public = $object->note_public;
+ $this->note_private = $object->note_private;
+ $this->note_public = $object->note_public;
}
- $this->module_source = $object->module_source;
+ $this->module_source = $object->module_source;
$this->pos_source = $object->pos_source;
$this->origin = $object->element;
$this->origin_id = $object->id;
- // get extrafields from original line
+ // get extrafields from original line
$object->fetch_optionals();
foreach ($object->array_options as $options_key => $value)
$this->array_options[$options_key] = $value;
@@ -1374,13 +1374,13 @@ class Facture extends CommonInvoice
* @param int $max Maxlength of ref
* @param int $short 1=Return just URL
* @param string $moretitle Add more text to title tooltip
- * @param int $notooltip 1=Disable tooltip
- * @param int $addlinktonotes 1=Add link to notes
- * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
- * @param string $target Target of link ('', '_self', '_blank', '_parent', '_backoffice', ...)
+ * @param int $notooltip 1=Disable tooltip
+ * @param int $addlinktonotes 1=Add link to notes
+ * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
+ * @param string $target Target of link ('', '_self', '_blank', '_parent', '_backoffice', ...)
* @return string String with URL
*/
- public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1, $target = '')
+ public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1, $target = '')
{
global $langs, $conf, $user, $mysoc;
@@ -1391,8 +1391,8 @@ class Facture extends CommonInvoice
if ($option == 'withdraw') $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id;
else $url = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->id;
- if (!$user->rights->facture->lire)
- $option = 'nolink';
+ if (!$user->rights->facture->lire)
+ $option = 'nolink';
if ($option !== 'nolink')
{
@@ -1408,56 +1408,56 @@ class Facture extends CommonInvoice
if ($this->type == self::TYPE_REPLACEMENT) $picto .= 'r'; // Replacement invoice
if ($this->type == self::TYPE_CREDIT_NOTE) $picto .= 'a'; // Credit note
if ($this->type == self::TYPE_DEPOSIT) $picto .= 'd'; // Deposit invoice
- $label = '';
+ $label = '';
- if ($user->rights->facture->lire) {
- $label = '
'.$langs->trans("Invoice").'';
- if ($this->type == self::TYPE_REPLACEMENT) $label = '
'.$langs->transnoentitiesnoconv("ReplacementInvoice").'';
- if ($this->type == self::TYPE_CREDIT_NOTE) $label = '
'.$langs->transnoentitiesnoconv("CreditNote").'';
- if ($this->type == self::TYPE_DEPOSIT) $label = '
'.$langs->transnoentitiesnoconv("Deposit").'';
- if ($this->type == self::TYPE_SITUATION) $label = '
'.$langs->transnoentitiesnoconv("InvoiceSituation").'';
- if (!empty($this->ref))
- $label .= '
'.$langs->trans('Ref').': '.$this->ref;
- if (!empty($this->ref_client))
- $label .= '
'.$langs->trans('RefCustomer').': '.$this->ref_client;
- if (!empty($this->date))
- $label .= '
'.$langs->trans('Date').': '.dol_print_date($this->date, 'day');
- if (!empty($this->total_ht))
- $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
- if (!empty($this->total_tva))
- $label .= '
'.$langs->trans('AmountVAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
- if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) // We keep test != 0 because $this->total_localtax1 can be '0.00000000'
- $label .= '
'.$langs->transcountry('AmountLT1', $mysoc->country_code).': '.price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
- if (!empty($this->total_localtax2) && $this->total_localtax2 != 0)
- $label .= '
'.$langs->transcountry('AmountLT2', $mysoc->country_code).': '.price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
- if (!empty($this->total_ttc))
- $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
- if ($moretitle) $label .= ' - '.$moretitle;
- if (isset($this->statut) && isset($this->alreadypaid)) {
- $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5, $this->alreadypaid);
- }
- }
+ if ($user->rights->facture->lire) {
+ $label = '
'.$langs->trans("Invoice").'';
+ if ($this->type == self::TYPE_REPLACEMENT) $label = '
'.$langs->transnoentitiesnoconv("ReplacementInvoice").'';
+ if ($this->type == self::TYPE_CREDIT_NOTE) $label = '
'.$langs->transnoentitiesnoconv("CreditNote").'';
+ if ($this->type == self::TYPE_DEPOSIT) $label = '
'.$langs->transnoentitiesnoconv("Deposit").'';
+ if ($this->type == self::TYPE_SITUATION) $label = '
'.$langs->transnoentitiesnoconv("InvoiceSituation").'';
+ if (!empty($this->ref))
+ $label .= '
'.$langs->trans('Ref').': '.$this->ref;
+ if (!empty($this->ref_client))
+ $label .= '
'.$langs->trans('RefCustomer').': '.$this->ref_client;
+ if (!empty($this->date))
+ $label .= '
'.$langs->trans('Date').': '.dol_print_date($this->date, 'day');
+ if (!empty($this->total_ht))
+ $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
+ if (!empty($this->total_tva))
+ $label .= '
'.$langs->trans('AmountVAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
+ if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) // We keep test != 0 because $this->total_localtax1 can be '0.00000000'
+ $label .= '
'.$langs->transcountry('AmountLT1', $mysoc->country_code).': '.price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
+ if (!empty($this->total_localtax2) && $this->total_localtax2 != 0)
+ $label .= '
'.$langs->transcountry('AmountLT2', $mysoc->country_code).': '.price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
+ if (!empty($this->total_ttc))
+ $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
+ if ($moretitle) $label .= ' - '.$moretitle;
+ if (isset($this->statut) && isset($this->alreadypaid)) {
+ $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5, $this->alreadypaid);
+ }
+ }
$linkclose = ($target ? ' target="'.$target.'"' : '');
if (empty($notooltip) && $user->rights->facture->lire)
{
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
- $label = $langs->trans("Invoice");
- $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
- }
- $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
- $linkclose .= ' class="classfortooltip"';
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
+ {
+ $label = $langs->trans("Invoice");
+ $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
+ }
+ $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
+ $linkclose .= ' class="classfortooltip"';
}
- $linkstart = '
';
+ $linkstart = '';
$linkend = '';
- if ($option == 'nolink') {
- $linkstart = '';
- $linkend = '';
- }
+ if ($option == 'nolink') {
+ $linkstart = '';
+ $linkend = '';
+ }
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
@@ -1466,19 +1466,19 @@ class Facture extends CommonInvoice
if ($addlinktonotes)
{
- $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
- if ($txttoshow)
- {
- //$notetoshow = $langs->trans("ViewPrivateNote").':
'.dol_string_nohtmltag($txttoshow, 1);
- $notetoshow = $langs->trans("ViewPrivateNote").':
'.$txttoshow;
- $result .= '
';
- $result .= '';
- $result .= img_picto('', 'note');
- $result .= '';
- //$result.=img_picto($langs->trans("ViewNote"),'object_generic');
- //$result.='';
- $result .= '';
- }
+ $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
+ if ($txttoshow)
+ {
+ //$notetoshow = $langs->trans("ViewPrivateNote").':
'.dol_string_nohtmltag($txttoshow, 1);
+ $notetoshow = $langs->trans("ViewPrivateNote").':
'.$txttoshow;
+ $result .= '
';
+ $result .= '';
+ $result .= img_picto('', 'note');
+ $result .= '';
+ //$result.=img_picto($langs->trans("ViewNote"),'object_generic');
+ //$result.='';
+ $result .= '';
+ }
}
return $result;
@@ -1516,10 +1516,10 @@ class Facture extends CommonInvoice
$sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
$sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
- $sql .= ', f.fk_incoterms, f.location_incoterms';
- $sql .= ', f.module_source, f.pos_source';
- $sql .= ", i.libelle as label_incoterms";
- $sql .= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit, f.retained_warranty_fk_cond_reglement as retained_warranty_fk_cond_reglement";
+ $sql .= ', f.fk_incoterms, f.location_incoterms';
+ $sql .= ', f.module_source, f.pos_source';
+ $sql .= ", i.libelle as label_incoterms";
+ $sql .= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit, f.retained_warranty_fk_cond_reglement as retained_warranty_fk_cond_reglement";
$sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
@@ -1651,7 +1651,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load all detailed lines into this->lines
*
@@ -1663,7 +1663,7 @@ class Facture extends CommonInvoice
public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
{
global $langs, $conf;
- // phpcs:enable
+ // phpcs:enable
$this->lines = array();
$sql = 'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
@@ -1708,7 +1708,7 @@ class Facture extends CommonInvoice
$line->subprice = $objp->subprice;
$line->ref_ext = $objp->ref_ext; // line external ref
- $line->vat_src_code = $objp->vat_src_code;
+ $line->vat_src_code = $objp->vat_src_code;
$line->tva_tx = $objp->tva_tx;
$line->localtax1_tx = $objp->localtax1_tx;
$line->localtax2_tx = $objp->localtax2_tx;
@@ -1751,14 +1751,14 @@ class Facture extends CommonInvoice
$line->multicurrency_total_tva = $objp->multicurrency_total_tva;
$line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
- $line->fetch_optionals();
+ $line->fetch_optionals();
// multilangs
- if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
- $line = new Product($this->db);
- $line->fetch($objp->fk_product);
- $line->getMultiLangs();
- }
+ if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
+ $line = new Product($this->db);
+ $line->fetch($objp->fk_product);
+ $line->getMultiLangs();
+ }
$this->lines[$i] = $line;
@@ -1778,7 +1778,7 @@ class Facture extends CommonInvoice
*
* @return void
*/
- public function fetchPreviousNextSituationInvoice()
+ public function fetchPreviousNextSituationInvoice()
{
global $conf;
@@ -1800,13 +1800,13 @@ class Facture extends CommonInvoice
$invoice = new Facture($this->db);
if ($invoice->fetch($objp->rowid) > 0)
{
- if ($objp->situation_counter < $this->situation_counter
- || ($objp->situation_counter == $this->situation_counter && $objp->rowid < $this->id) // This case appear when there are credit notes
- )
+ if ($objp->situation_counter < $this->situation_counter
+ || ($objp->situation_counter == $this->situation_counter && $objp->rowid < $this->id) // This case appear when there are credit notes
+ )
{
- $this->tab_previous_situation_invoice[] = $invoice;
+ $this->tab_previous_situation_invoice[] = $invoice;
} else {
- $this->tab_next_situation_invoice[] = $invoice;
+ $this->tab_next_situation_invoice[] = $invoice;
}
}
}
@@ -1820,7 +1820,7 @@ class Facture extends CommonInvoice
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
- public function update(User $user, $notrigger = 0)
+ public function update(User $user, $notrigger = 0)
{
global $conf;
@@ -1930,16 +1930,16 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Add a discount line into an invoice (as an invoice line) using an existing absolute discount (Consume the discount)
*
* @param int $idremise Id of absolute discount
* @return int >0 if OK, <0 if KO
*/
- public function insert_discount($idremise)
+ public function insert_discount($idremise)
{
- // phpcs:enable
+ // phpcs:enable
global $langs;
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@@ -1975,12 +1975,12 @@ class Facture extends CommonInvoice
// Get buy/cost price of invoice that is source of discount
if ($remise->fk_facture_source > 0)
{
- $srcinvoice = new Facture($this->db);
- $srcinvoice->fetch($remise->fk_facture_source);
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; // TODO Move this into commonobject
- $formmargin = new FormMargin($this->db);
- $arraytmp = $formmargin->getMarginInfosArray($srcinvoice, false);
- $facligne->pa_ht = $arraytmp['pa_total'];
+ $srcinvoice = new Facture($this->db);
+ $srcinvoice->fetch($remise->fk_facture_source);
+ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; // TODO Move this into commonobject
+ $formmargin = new FormMargin($this->db);
+ $arraytmp = $formmargin->getMarginInfosArray($srcinvoice, false);
+ $facligne->pa_ht = $arraytmp['pa_total'];
}
$facligne->total_ht = -$remise->amount_ht;
@@ -2025,7 +2025,7 @@ class Facture extends CommonInvoice
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Set customer ref
*
@@ -2033,10 +2033,10 @@ class Facture extends CommonInvoice
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if KO, >0 if OK
*/
- public function set_ref_client($ref_client, $notrigger = 0)
+ public function set_ref_client($ref_client, $notrigger = 0)
{
- // phpcs:enable
- global $user;
+ // phpcs:enable
+ global $user;
$error = 0;
@@ -2094,7 +2094,7 @@ class Facture extends CommonInvoice
* @param int $idwarehouse Id warehouse to use for stock change.
* @return int <0 if KO, 0=Refused, >0 if OK
*/
- public function delete($user, $notrigger = 0, $idwarehouse = -1)
+ public function delete($user, $notrigger = 0, $idwarehouse = -1)
{
global $langs, $conf;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -2114,10 +2114,10 @@ class Facture extends CommonInvoice
if (!$error && !$notrigger)
{
- // Call trigger
- $result = $this->call_trigger('BILL_DELETE', $user);
- if ($result < 0) $error++;
- // End call triggers
+ // Call trigger
+ $result = $this->call_trigger('BILL_DELETE', $user);
+ if ($result < 0) $error++;
+ // End call triggers
}
// Removed extrafields
@@ -2189,7 +2189,7 @@ class Facture extends CommonInvoice
}
}
- // Invoice line extrafileds
+ // Invoice line extrafileds
$main = MAIN_DB_PREFIX.'facturedet';
$ef = $main."_extrafields";
$sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture = $rowid)";
@@ -2255,7 +2255,7 @@ class Facture extends CommonInvoice
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Tag the invoice as paid completely (if close_code is filled) => this->fk_statut=2, this->paye=1
* or partialy (if close_code filled) + appel trigger BILL_PAYED => this->fk_statut=2, this->paye stay 0
@@ -2265,9 +2265,9 @@ class Facture extends CommonInvoice
* @param string $close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple)
* @return int <0 if KO, >0 if OK
*/
- public function set_paid($user, $close_code = '', $close_note = '')
+ public function set_paid($user, $close_code = '', $close_note = '')
{
- // phpcs:enable
+ // phpcs:enable
$error = 0;
if ($this->paye != 1)
@@ -2290,10 +2290,10 @@ class Facture extends CommonInvoice
$resql = $this->db->query($sql);
if ($resql)
{
- // Call trigger
- $result = $this->call_trigger('BILL_PAYED', $user);
- if ($result < 0) $error++;
- // End call triggers
+ // Call trigger
+ $result = $this->call_trigger('BILL_PAYED', $user);
+ if ($result < 0) $error++;
+ // End call triggers
} else {
$error++;
$this->error = $this->db->lasterror();
@@ -2313,7 +2313,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Tag la facture comme non payee completement + appel trigger BILL_UNPAYED
* Fonction utilisee quand un paiement prelevement est refuse,
@@ -2322,9 +2322,9 @@ class Facture extends CommonInvoice
* @param User $user Object user that change status
* @return int <0 if KO, >0 if OK
*/
- public function set_unpaid($user)
+ public function set_unpaid($user)
{
- // phpcs:enable
+ // phpcs:enable
$error = 0;
$this->db->begin();
@@ -2339,10 +2339,10 @@ class Facture extends CommonInvoice
$resql = $this->db->query($sql);
if ($resql)
{
- // Call trigger
- $result = $this->call_trigger('BILL_UNPAYED', $user);
- if ($result < 0) $error++;
- // End call triggers
+ // Call trigger
+ $result = $this->call_trigger('BILL_UNPAYED', $user);
+ if ($result < 0) $error++;
+ // End call triggers
} else {
$error++;
$this->error = $this->db->error();
@@ -2360,7 +2360,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Tag invoice as canceled, with no payment on it (example for replacement invoice or payment never received) + call trigger BILL_CANCEL
* Warning, if option to decrease stock on invoice was set, this function does not change stock (it might be a cancel because
@@ -2371,9 +2371,9 @@ class Facture extends CommonInvoice
* @param string $close_note Comment
* @return int <0 if KO, >0 if OK
*/
- public function set_canceled($user, $close_code = '', $close_note = '')
+ public function set_canceled($user, $close_code = '', $close_note = '')
{
- // phpcs:enable
+ // phpcs:enable
dol_syslog(get_class($this)."::set_canceled rowid=".$this->id, LOG_DEBUG);
@@ -2397,14 +2397,14 @@ class Facture extends CommonInvoice
$resql = $this->db->query($sql);
if ($resql)
{
- // Call trigger
- $result = $this->call_trigger('BILL_CANCEL', $user);
- if ($result < 0)
- {
+ // Call trigger
+ $result = $this->call_trigger('BILL_CANCEL', $user);
+ if ($result < 0)
+ {
$this->db->rollback();
return -1;
}
- // End call triggers
+ // End call triggers
$this->db->commit();
return 1;
@@ -2430,9 +2430,9 @@ class Facture extends CommonInvoice
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @param int $batch_rule 0=do not decrement batch, else batch rule to use
* 1=take in batches ordered by sellby and eatby dates
- * @return int <0 if KO, 0=Nothing done because invoice is not a draft, >0 if OK
+ * @return int <0 if KO, 0=Nothing done because invoice is not a draft, >0 if OK
*/
- public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0, $batch_rule = 0)
+ public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0, $batch_rule = 0)
{
global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -2463,12 +2463,12 @@ class Facture extends CommonInvoice
}
if (count($this->lines) <= 0)
{
- $langs->load("errors");
+ $langs->load("errors");
$this->error = $langs->trans("ErrorObjectMustHaveLinesToBeValidated", $this->ref);
return -1;
}
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->creer))
- || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->invoice_advance->validate)))
+ || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->invoice_advance->validate)))
{
$this->error = 'Permission denied';
dol_syslog(get_class($this)."::validate ".$this->error.' MAIN_USE_ADVANCED_PERMS='.$conf->global->MAIN_USE_ADVANCED_PERMS, LOG_ERR);
@@ -2680,10 +2680,10 @@ class Facture extends CommonInvoice
// Trigger calls
if (!$error && !$notrigger)
{
- // Call trigger
- $result = $this->call_trigger('BILL_VALIDATE', $user);
- if ($result < 0) $error++;
- // End call triggers
+ // Call trigger
+ $result = $this->call_trigger('BILL_VALIDATE', $user);
+ if ($result < 0) $error++;
+ // End call triggers
}
if (!$error)
@@ -2711,16 +2711,16 @@ class Facture extends CommonInvoice
if (@rename($dirsource, $dirdest))
{
dol_syslog("Rename ok");
- // Rename docs starting with $oldref with $newref
- $listoffiles = dol_dir_list($conf->facture->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
- foreach ($listoffiles as $fileentry)
- {
- $dirsource = $fileentry['name'];
- $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
- $dirsource = $fileentry['path'].'/'.$dirsource;
- $dirdest = $fileentry['path'].'/'.$dirdest;
- @rename($dirsource, $dirdest);
- }
+ // Rename docs starting with $oldref with $newref
+ $listoffiles = dol_dir_list($conf->facture->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
+ foreach ($listoffiles as $fileentry)
+ {
+ $dirsource = $fileentry['name'];
+ $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
+ $dirsource = $fileentry['path'].'/'.$dirsource;
+ $dirdest = $fileentry['path'].'/'.$dirdest;
+ @rename($dirsource, $dirdest);
+ }
}
}
}
@@ -2744,20 +2744,20 @@ class Facture extends CommonInvoice
$this->date_validation = $now;
$i = 0;
- if (!empty($conf->global->INVOICE_USE_SITUATION))
- {
- $final = true;
- $nboflines = count($this->lines);
- while (($i < $nboflines) && $final) {
- $final = ($this->lines[$i]->situation_percent == 100);
- $i++;
- }
+ if (!empty($conf->global->INVOICE_USE_SITUATION))
+ {
+ $final = true;
+ $nboflines = count($this->lines);
+ while (($i < $nboflines) && $final) {
+ $final = ($this->lines[$i]->situation_percent == 100);
+ $i++;
+ }
- if (empty($final)) $this->situation_final = 0;
- else $this->situation_final = 1;
+ if (empty($final)) $this->situation_final = 0;
+ else $this->situation_final = 1;
- $this->setFinal($user);
- }
+ $this->setFinal($user);
+ }
}
} else {
$error++;
@@ -2779,7 +2779,7 @@ class Facture extends CommonInvoice
* @param Translate $langs Translate object
* @return bool false if KO, true if OK
*/
- public function updatePriceNextInvoice(&$langs)
+ public function updatePriceNextInvoice(&$langs)
{
foreach ($this->tab_next_situation_invoice as $next_invoice)
{
@@ -2823,7 +2823,7 @@ class Facture extends CommonInvoice
*/
public function setDraft($user, $idwarehouse = -1)
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $langs;
$error = 0;
@@ -2945,38 +2945,38 @@ class Facture extends CommonInvoice
* @param string $ref_ext External reference of the line
* @return int <0 if KO, Id of line if OK
*/
- public function addline(
- $desc,
- $pu_ht,
- $qty,
- $txtva,
- $txlocaltax1 = 0,
- $txlocaltax2 = 0,
- $fk_product = 0,
- $remise_percent = 0,
- $date_start = '',
- $date_end = '',
- $ventil = 0,
- $info_bits = 0,
- $fk_remise_except = '',
- $price_base_type = 'HT',
- $pu_ttc = 0,
- $type = self::TYPE_STANDARD,
- $rang = -1,
- $special_code = 0,
- $origin = '',
- $origin_id = 0,
- $fk_parent_line = 0,
- $fk_fournprice = null,
- $pa_ht = 0,
- $label = '',
- $array_options = 0,
- $situation_percent = 100,
- $fk_prev_id = 0,
- $fk_unit = null,
- $pu_ht_devise = 0,
- $ref_ext = ''
- ) {
+ public function addline(
+ $desc,
+ $pu_ht,
+ $qty,
+ $txtva,
+ $txlocaltax1 = 0,
+ $txlocaltax2 = 0,
+ $fk_product = 0,
+ $remise_percent = 0,
+ $date_start = '',
+ $date_end = '',
+ $ventil = 0,
+ $info_bits = 0,
+ $fk_remise_except = '',
+ $price_base_type = 'HT',
+ $pu_ttc = 0,
+ $type = self::TYPE_STANDARD,
+ $rang = -1,
+ $special_code = 0,
+ $origin = '',
+ $origin_id = 0,
+ $fk_parent_line = 0,
+ $fk_fournprice = null,
+ $pa_ht = 0,
+ $label = '',
+ $array_options = 0,
+ $situation_percent = 100,
+ $fk_prev_id = 0,
+ $fk_unit = null,
+ $pu_ht_devise = 0,
+ $ref_ext = ''
+ ) {
// Deprecation warning
if ($label) {
dol_syslog(__METHOD__.": using line label is deprecated", LOG_WARNING);
@@ -3043,8 +3043,8 @@ class Facture extends CommonInvoice
$product_type = $product->type;
if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) {
- $langs->load("errors");
- $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
+ $langs->load("errors");
+ $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
$this->db->rollback();
return -3;
}
@@ -3077,8 +3077,8 @@ class Facture extends CommonInvoice
// MultiCurrency
$multicurrency_total_ht = $tabprice[16];
- $multicurrency_total_tva = $tabprice[17];
- $multicurrency_total_ttc = $tabprice[18];
+ $multicurrency_total_tva = $tabprice[17];
+ $multicurrency_total_ttc = $tabprice[18];
$pu_ht_devise = $tabprice[19];
// Rank to use
@@ -3142,8 +3142,8 @@ class Facture extends CommonInvoice
$this->line->multicurrency_code = $this->multicurrency_code;
$this->line->multicurrency_subprice = $pu_ht_devise;
$this->line->multicurrency_total_ht = $multicurrency_total_ht;
- $this->line->multicurrency_total_tva = $multicurrency_total_tva;
- $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
+ $this->line->multicurrency_total_tva = $multicurrency_total_tva;
+ $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
if (is_array($array_options) && count($array_options) > 0) {
$this->line->array_options = $array_options;
@@ -3200,7 +3200,7 @@ class Facture extends CommonInvoice
* @param int $pa_ht Price (without tax) of product when it was bought
* @param string $label Label of the line (deprecated, do not use)
* @param int $special_code Special code (also used by externals modules!)
- * @param array $array_options extrafields array
+ * @param array $array_options extrafields array
* @param int $situation_percent Situation advance percentage
* @param string $fk_unit Code of the unit to use. Null to use the default one
* @param double $pu_ht_devise Unit price in currency
@@ -3208,7 +3208,7 @@ class Facture extends CommonInvoice
* @param string $ref_ext External reference of the line
* @return int < 0 if KO, > 0 if OK
*/
- public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $info_bits = 0, $type = self::TYPE_STANDARD, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $special_code = 0, $array_options = 0, $situation_percent = 100, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $ref_ext = '')
+ public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $info_bits = 0, $type = self::TYPE_STANDARD, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $special_code = 0, $array_options = 0, $situation_percent = 100, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $ref_ext = '')
{
global $conf, $user;
// Deprecation warning
@@ -3251,7 +3251,7 @@ class Facture extends CommonInvoice
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
$pu = price2num($pu);
- $pu_ht_devise = price2num($pu_ht_devise);
+ $pu_ht_devise = price2num($pu_ht_devise);
$pa_ht = price2num($pa_ht);
$txtva = price2num($txtva);
$txlocaltax1 = price2num($txlocaltax1);
@@ -3267,12 +3267,12 @@ class Facture extends CommonInvoice
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
// Clean vat code
- $vat_src_code = '';
- if (preg_match('/\((.*)\)/', $txtva, $reg))
- {
- $vat_src_code = $reg[1];
- $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
- }
+ $vat_src_code = '';
+ if (preg_match('/\((.*)\)/', $txtva, $reg))
+ {
+ $vat_src_code = $reg[1];
+ $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
+ }
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx, $pu_ht_devise);
@@ -3287,8 +3287,8 @@ class Facture extends CommonInvoice
// MultiCurrency
$multicurrency_total_ht = $tabprice[16];
- $multicurrency_total_tva = $tabprice[17];
- $multicurrency_total_ttc = $tabprice[18];
+ $multicurrency_total_tva = $tabprice[17];
+ $multicurrency_total_ttc = $tabprice[18];
$pu_ht_devise = $tabprice[19];
// Old properties: $price, $remise (deprecated)
@@ -3313,8 +3313,8 @@ class Facture extends CommonInvoice
$product_type = $product->type;
if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) {
- $langs->load("errors");
- $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
+ $langs->load("errors");
+ $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
$this->db->rollback();
return -3;
}
@@ -3324,7 +3324,7 @@ class Facture extends CommonInvoice
$line->oldline = $staticline;
$this->line = $line;
- $this->line->context = $this->context;
+ $this->line->context = $this->context;
// Reorder if fk_parent_line change
if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
@@ -3337,7 +3337,7 @@ class Facture extends CommonInvoice
$this->line->rowid = $rowid;
$this->line->label = $label;
$this->line->desc = $desc;
- $this->line->ref_ext = $ref_ext;
+ $this->line->ref_ext = $ref_ext;
$this->line->qty = ($this->type == self::TYPE_CREDIT_NOTE ?abs($qty) : $qty); // For credit note, quantity is always positive and unit price negative
$this->line->vat_src_code = $vat_src_code;
@@ -3370,8 +3370,8 @@ class Facture extends CommonInvoice
// Multicurrency
$this->line->multicurrency_subprice = $pu_ht_devise;
$this->line->multicurrency_total_ht = $multicurrency_total_ht;
- $this->line->multicurrency_total_tva = $multicurrency_total_tva;
- $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
+ $this->line->multicurrency_total_tva = $multicurrency_total_tva;
+ $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
if (is_array($array_options) && count($array_options) > 0) {
// We replace values in this->line->array_options only for entries defined into $array_options
@@ -3391,7 +3391,7 @@ class Facture extends CommonInvoice
$this->db->commit();
return $result;
} else {
- $this->error = $this->line->error;
+ $this->error = $this->line->error;
$this->db->rollback();
return -1;
}
@@ -3408,7 +3408,7 @@ class Facture extends CommonInvoice
* @param float $situation_percent progress percentage need to be test
* @return false if KO, true if OK
*/
- public function checkProgressLine($idline, $situation_percent)
+ public function checkProgressLine($idline, $situation_percent)
{
$sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd
INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (fd.fk_facture = f.rowid)
@@ -3428,7 +3428,7 @@ class Facture extends CommonInvoice
else return $situation_percent < $obj->situation_percent;
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Update invoice line with percentage
*
@@ -3436,16 +3436,16 @@ class Facture extends CommonInvoice
* @param int $percent Percentage
* @return void
*/
- public function update_percent($line, $percent)
+ public function update_percent($line, $percent)
{
- // phpcs:enable
- global $mysoc, $user;
+ // phpcs:enable
+ global $mysoc, $user;
- // Progress should never be changed for discount lines
- if (($line->info_bits & 2) == 2)
- {
- return;
- }
+ // Progress should never be changed for discount lines
+ if (($line->info_bits & 2) == 2)
+ {
+ return;
+ }
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@@ -3471,9 +3471,9 @@ class Facture extends CommonInvoice
* @param int $rowid Id of line to delete
* @return int <0 if KO, >0 if OK
*/
- public function deleteline($rowid)
+ public function deleteline($rowid)
{
- global $user;
+ global $user;
dol_syslog(get_class($this)."::deleteline rowid=".$rowid, LOG_DEBUG);
@@ -3501,7 +3501,7 @@ class Facture extends CommonInvoice
$line = new FactureLigne($this->db);
- $line->context = $this->context;
+ $line->context = $this->context;
// For triggers
$result = $line->fetch($rowid);
@@ -3527,7 +3527,7 @@ class Facture extends CommonInvoice
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Set percent discount
*
@@ -3536,9 +3536,9 @@ class Facture extends CommonInvoice
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if ko, >0 if ok
*/
- public function set_remise($user, $remise, $notrigger = 0)
+ public function set_remise($user, $remise, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
// Clean parameters
if (empty($remise)) $remise = 0;
@@ -3591,7 +3591,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Set absolute discount
*
@@ -3600,9 +3600,9 @@ class Facture extends CommonInvoice
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if KO, >0 if OK
*/
- public function set_remise_absolue($user, $remise, $notrigger = 0)
+ public function set_remise_absolue($user, $remise, $notrigger = 0)
{
- // phpcs:enable
+ // phpcs:enable
if (empty($remise)) $remise = 0;
if ($user->rights->facture->creer)
@@ -3665,7 +3665,7 @@ class Facture extends CommonInvoice
* @param string $mode 'next' for next value or 'last' for last value
* @return string free ref or last ref
*/
- public function getNextNumRef($soc, $mode = 'next')
+ public function getNextNumRef($soc, $mode = 'next')
{
global $conf, $langs;
@@ -3763,7 +3763,7 @@ class Facture extends CommonInvoice
* @param int $id Id of object to load
* @return void
*/
- public function info($id)
+ public function info($id)
{
$sql = 'SELECT c.rowid, datec, date_valid as datev, tms as datem,';
$sql .= ' date_closing as dateclosing,';
@@ -3809,7 +3809,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of invoices (eventually filtered on a user) into an array
*
@@ -3823,9 +3823,9 @@ class Facture extends CommonInvoice
* @param string $sortorder Sort order
* @return array|int -1 if KO, array with result if OK
*/
- public function liste_array($shortlist = 0, $draft = 0, $excluser = '', $socid = 0, $limit = 0, $offset = 0, $sortfield = 'f.datef,f.rowid', $sortorder = 'DESC')
+ public function liste_array($shortlist = 0, $draft = 0, $excluser = '', $socid = 0, $limit = 0, $offset = 0, $sortfield = 'f.datef,f.rowid', $sortorder = 'DESC')
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $user;
$ga = array();
@@ -3880,7 +3880,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of invoices qualified to be replaced by another invoice.
* Invoices matching the following rules are returned:
@@ -3889,9 +3889,9 @@ class Facture extends CommonInvoice
* @param int $socid Id thirdparty
* @return array|int Array of invoices ('id'=>id, 'ref'=>ref, 'status'=>status, 'paymentornot'=>0/1)
*/
- public function list_replacable_invoices($socid = 0)
+ public function list_replacable_invoices($socid = 0)
{
- // phpcs:enable
+ // phpcs:enable
global $conf;
$return = array();
@@ -3928,7 +3928,7 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of invoices qualified to be corrected by a credit note.
* Invoices matching the following rules are returned:
@@ -3937,9 +3937,9 @@ class Facture extends CommonInvoice
* @param int $socid Id thirdparty
* @return array Array of invoices ($id => array('ref'=>,'paymentornot'=>,'status'=>,'paye'=>)
*/
- public function list_qualified_avoir_invoices($socid = 0)
+ public function list_qualified_avoir_invoices($socid = 0)
{
- // phpcs:enable
+ // phpcs:enable
global $conf;
$return = array();
@@ -3958,17 +3958,17 @@ class Facture extends CommonInvoice
$sql .= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir
if (!empty($conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE)) {
- // Select the last situation invoice
- $sqlSit = 'SELECT MAX(fs.rowid)';
- $sqlSit .= " FROM ".MAIN_DB_PREFIX."facture as fs";
- $sqlSit .= " WHERE fs.entity IN (".getEntity('invoice').")";
- $sqlSit .= " AND fs.type = ".self::TYPE_SITUATION;
- $sqlSit .= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
- $sqlSit .= " GROUP BY fs.situation_cycle_ref";
- $sqlSit .= " ORDER BY fs.situation_counter";
- $sql .= " AND ( f.type != ".self::TYPE_SITUATION." OR f.rowid IN (".$sqlSit.") )"; // Type non 5 si facture non avoir
+ // Select the last situation invoice
+ $sqlSit = 'SELECT MAX(fs.rowid)';
+ $sqlSit .= " FROM ".MAIN_DB_PREFIX."facture as fs";
+ $sqlSit .= " WHERE fs.entity IN (".getEntity('invoice').")";
+ $sqlSit .= " AND fs.type = ".self::TYPE_SITUATION;
+ $sqlSit .= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
+ $sqlSit .= " GROUP BY fs.situation_cycle_ref";
+ $sqlSit .= " ORDER BY fs.situation_counter";
+ $sql .= " AND ( f.type != ".self::TYPE_SITUATION." OR f.rowid IN (".$sqlSit.") )"; // Type non 5 si facture non avoir
} else {
- $sql .= " AND f.type != ".self::TYPE_SITUATION; // Type non 5 si facture non avoir
+ $sql .= " AND f.type != ".self::TYPE_SITUATION; // Type non 5 si facture non avoir
}
if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
@@ -3999,16 +3999,16 @@ class Facture extends CommonInvoice
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
*
* @param User $user Object user
* @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
*/
- public function load_board($user)
+ public function load_board($user)
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $langs;
$clause = " WHERE";
@@ -4071,7 +4071,7 @@ class Facture extends CommonInvoice
*
* @return array Liste des id contacts facturation
*/
- public function getIdBillingContact()
+ public function getIdBillingContact()
{
return $this->getIdContact('external', 'BILLING');
}
@@ -4081,7 +4081,7 @@ class Facture extends CommonInvoice
*
* @return array Liste des id contacts livraison
*/
- public function getIdShippingContact()
+ public function getIdShippingContact()
{
return $this->getIdContact('external', 'SHIPPING');
}
@@ -4095,7 +4095,7 @@ class Facture extends CommonInvoice
* @param string $option ''=Create a specimen invoice with lines, 'nolines'=No lines
* @return void
*/
- public function initAsSpecimen($option = '')
+ public function initAsSpecimen($option = '')
{
global $conf, $langs;
@@ -4103,7 +4103,7 @@ class Facture extends CommonInvoice
$arraynow = dol_getdate($now);
$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
- // Load array of products prodids
+ // Load array of products prodids
$num_prods = 0;
$prodids = array();
$sql = "SELECT rowid";
@@ -4250,15 +4250,15 @@ class Facture extends CommonInvoice
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
*
* @return int <0 if KO, >0 if OK
*/
- public function load_state_board()
+ public function load_state_board()
{
- // phpcs:enable
+ // phpcs:enable
global $conf, $user;
$this->nb = array();
@@ -4283,7 +4283,7 @@ class Facture extends CommonInvoice
{
$this->nb["invoices"] = $obj->nb;
}
- $this->db->free($resql);
+ $this->db->free($resql);
return 1;
} else {
dol_print_error($this->db);
@@ -4297,9 +4297,9 @@ class Facture extends CommonInvoice
*
* @return int >0 if OK, <0 if KO
*/
- public function getLinesArray()
+ public function getLinesArray()
{
- return $this->fetch_lines();
+ return $this->fetch_lines();
}
/**
@@ -4344,7 +4344,7 @@ class Facture extends CommonInvoice
*
* @return int >= 1 if OK, -1 if error
*/
- public function newCycle()
+ public function newCycle()
{
$sql = 'SELECT max(situation_cycle_ref) FROM '.MAIN_DB_PREFIX.'facture as f';
$sql .= " WHERE f.entity IN (".getEntity('invoice', 0).")";
@@ -4367,27 +4367,27 @@ class Facture extends CommonInvoice
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Checks if the invoice is the first of a cycle
*
* @return boolean
*/
- public function is_first()
+ public function is_first()
{
- // phpcs:enable
+ // phpcs:enable
return ($this->situation_counter == 1);
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Returns an array containing the previous situations as Facture objects
*
* @return mixed -1 if error, array of previous situations
*/
- public function get_prev_sits()
+ public function get_prev_sits()
{
- // phpcs:enable
+ // phpcs:enable
global $conf;
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture';
@@ -4419,7 +4419,7 @@ class Facture extends CommonInvoice
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if KO, >0 if OK
*/
- public function setFinal(User $user, $notrigger = 0)
+ public function setFinal(User $user, $notrigger = 0)
{
$error = 0;
@@ -4458,15 +4458,15 @@ class Facture extends CommonInvoice
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Checks if the invoice is the last in its cycle
*
* @return bool Last of the cycle status
*/
- public function is_last_in_cycle()
+ public function is_last_in_cycle()
{
- // phpcs:enable
+ // phpcs:enable
global $conf;
if (!empty($this->situation_cycle_ref)) {
@@ -4524,21 +4524,21 @@ class Facture extends CommonInvoice
$hasDelay = $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay);
if ($hasDelay && !empty($this->retained_warranty) && !empty($this->retained_warranty_date_limit))
{
- $totalpaye = $this->getSommePaiement();
- $totalpaye = floatval($totalpaye);
- $RetainedWarrantyAmount = $this->getRetainedWarrantyAmount();
- if ($totalpaye >= 0 && $RetainedWarrantyAmount >= 0)
- {
- if (($totalpaye < $this->total_ttc - $RetainedWarrantyAmount) && $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay))
- {
- $hasDelay = 1;
- } elseif ($totalpaye < $this->total_ttc && $this->retained_warranty_date_limit < ($now - $conf->facture->client->warning_delay))
- {
- $hasDelay = 1;
- } else {
- $hasDelay = 0;
- }
- }
+ $totalpaye = $this->getSommePaiement();
+ $totalpaye = floatval($totalpaye);
+ $RetainedWarrantyAmount = $this->getRetainedWarrantyAmount();
+ if ($totalpaye >= 0 && $RetainedWarrantyAmount >= 0)
+ {
+ if (($totalpaye < $this->total_ttc - $RetainedWarrantyAmount) && $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay))
+ {
+ $hasDelay = 1;
+ } elseif ($totalpaye < $this->total_ttc && $this->retained_warranty_date_limit < ($now - $conf->facture->client->warning_delay))
+ {
+ $hasDelay = 1;
+ } else {
+ $hasDelay = 0;
+ }
+ }
}
return $hasDelay;
@@ -4589,45 +4589,45 @@ class Facture extends CommonInvoice
public function getRetainedWarrantyAmount($rounding = -1)
{
global $conf;
- if (empty($this->retained_warranty)) {
- return -1;
- }
+ if (empty($this->retained_warranty)) {
+ return -1;
+ }
- $retainedWarrantyAmount = 0;
+ $retainedWarrantyAmount = 0;
- // Billed - retained warranty
- if ($this->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION))
- {
- $displayWarranty = true;
- // Check if this situation invoice is 100% for real
- if (!empty($this->lines)) {
- foreach ($this->lines as $i => $line) {
- if ($line->product_type < 2 && $line->situation_percent < 100) {
- $displayWarranty = false;
- break;
- }
- }
- }
+ // Billed - retained warranty
+ if ($this->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION))
+ {
+ $displayWarranty = true;
+ // Check if this situation invoice is 100% for real
+ if (!empty($this->lines)) {
+ foreach ($this->lines as $i => $line) {
+ if ($line->product_type < 2 && $line->situation_percent < 100) {
+ $displayWarranty = false;
+ break;
+ }
+ }
+ }
- if ($displayWarranty && !empty($this->situation_final))
- {
- $this->fetchPreviousNextSituationInvoice();
- $TPreviousIncoice = $this->tab_previous_situation_invoice;
+ if ($displayWarranty && !empty($this->situation_final))
+ {
+ $this->fetchPreviousNextSituationInvoice();
+ $TPreviousIncoice = $this->tab_previous_situation_invoice;
- $total2BillWT = 0;
- foreach ($TPreviousIncoice as &$fac) {
- $total2BillWT += $fac->total_ttc;
- }
- $total2BillWT += $this->total_ttc;
+ $total2BillWT = 0;
+ foreach ($TPreviousIncoice as &$fac) {
+ $total2BillWT += $fac->total_ttc;
+ }
+ $total2BillWT += $this->total_ttc;
- $retainedWarrantyAmount = $total2BillWT * $this->retained_warranty / 100;
- } else {
- return -1;
- }
- } else {
- // Because one day retained warranty could be used on standard invoices
- $retainedWarrantyAmount = $this->total_ttc * $this->retained_warranty / 100;
- }
+ $retainedWarrantyAmount = $total2BillWT * $this->retained_warranty / 100;
+ } else {
+ return -1;
+ }
+ } else {
+ // Because one day retained warranty could be used on standard invoices
+ $retainedWarrantyAmount = $this->total_ttc * $this->retained_warranty / 100;
+ }
if ($rounding < 0) {
$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
@@ -4637,7 +4637,7 @@ class Facture extends CommonInvoice
return round($retainedWarrantyAmount, $rounding);
}
- return $retainedWarrantyAmount;
+ return $retainedWarrantyAmount;
}
/**
@@ -4648,28 +4648,28 @@ class Facture extends CommonInvoice
*/
public function setRetainedWarranty($value)
{
- dol_syslog(get_class($this).'::setRetainedWarranty('.$value.')');
- if ($this->statut >= 0)
- {
- $fieldname = 'retained_warranty';
- $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
- $sql .= ' SET '.$fieldname.' = '.floatval($value);
- $sql .= ' WHERE rowid='.$this->id;
+ dol_syslog(get_class($this).'::setRetainedWarranty('.$value.')');
+ if ($this->statut >= 0)
+ {
+ $fieldname = 'retained_warranty';
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+ $sql .= ' SET '.$fieldname.' = '.floatval($value);
+ $sql .= ' WHERE rowid='.$this->id;
- if ($this->db->query($sql))
- {
- $this->retained_warranty = floatval($value);
- return 1;
- } else {
- dol_syslog(get_class($this).'::setRetainedWarranty Erreur '.$sql.' - '.$this->db->error());
- $this->error = $this->db->error();
- return -1;
- }
- } else {
- dol_syslog(get_class($this).'::setRetainedWarranty, status of the object is incompatible');
- $this->error = 'Status of the object is incompatible '.$this->statut;
- return -2;
- }
+ if ($this->db->query($sql))
+ {
+ $this->retained_warranty = floatval($value);
+ return 1;
+ } else {
+ dol_syslog(get_class($this).'::setRetainedWarranty Erreur '.$sql.' - '.$this->db->error());
+ $this->error = $this->db->error();
+ return -1;
+ }
+ } else {
+ dol_syslog(get_class($this).'::setRetainedWarranty, status of the object is incompatible');
+ $this->error = 'Status of the object is incompatible '.$this->statut;
+ return -2;
+ }
}
@@ -4682,33 +4682,33 @@ class Facture extends CommonInvoice
*/
public function setRetainedWarrantyDateLimit($timestamp, $dateYmd = false)
{
- if (!$timestamp && $dateYmd) {
- $timestamp = $this->db->jdate($dateYmd);
- }
+ if (!$timestamp && $dateYmd) {
+ $timestamp = $this->db->jdate($dateYmd);
+ }
- dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit('.$timestamp.')');
- if ($this->statut >= 0)
- {
- $fieldname = 'retained_warranty_date_limit';
- $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
- $sql .= ' SET '.$fieldname.' = '.(strval($timestamp) != '' ? '\''.$this->db->idate($timestamp).'\'' : 'null');
- $sql .= ' WHERE rowid='.$this->id;
+ dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit('.$timestamp.')');
+ if ($this->statut >= 0)
+ {
+ $fieldname = 'retained_warranty_date_limit';
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+ $sql .= ' SET '.$fieldname.' = '.(strval($timestamp) != '' ? '\''.$this->db->idate($timestamp).'\'' : 'null');
+ $sql .= ' WHERE rowid='.$this->id;
- if ($this->db->query($sql))
- {
- $this->retained_warranty_date_limit = $timestamp;
- return 1;
- } else {
- dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit Erreur '.$sql.' - '.$this->db->error());
- $this->error = $this->db->error();
- return -1;
- }
- } else {
- dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit, status of the object is incompatible');
- $this->error = 'Status of the object is incompatible '.$this->statut;
- return -2;
- }
+ if ($this->db->query($sql))
+ {
+ $this->retained_warranty_date_limit = $timestamp;
+ return 1;
+ } else {
+ dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit Erreur '.$sql.' - '.$this->db->error());
+ $this->error = $this->db->error();
+ return -1;
+ }
+ } else {
+ dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit, status of the object is incompatible');
+ $this->error = 'Status of the object is incompatible '.$this->statut;
+ return -2;
+ }
}
}
@@ -4718,12 +4718,12 @@ class Facture extends CommonInvoice
*/
class FactureLigne extends CommonInvoiceLine
{
- /**
+ /**
* @var string ID to identify managed object
*/
public $element = 'facturedet';
- /**
+ /**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'facturedet';
@@ -4809,7 +4809,7 @@ class FactureLigne extends CommonInvoiceLine
* @param int $rowid id of invoice line to get
* @return int <0 if KO, >0 if OK
*/
- public function fetch($rowid)
+ public function fetch($rowid)
{
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.vat_src_code, fd.tva_tx,';
$sql .= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice, fd.ref_ext,';
@@ -4888,7 +4888,7 @@ class FactureLigne extends CommonInvoiceLine
return 1;
} else {
- $this->error = $this->db->lasterror();
+ $this->error = $this->db->lasterror();
return -1;
}
}
@@ -4900,15 +4900,15 @@ class FactureLigne extends CommonInvoiceLine
* @param int $noerrorifdiscountalreadylinked 1=Do not make error if lines is linked to a discount and discount already linked to another
* @return int <0 if KO, >0 if OK
*/
- public function insert($notrigger = 0, $noerrorifdiscountalreadylinked = 0)
+ public function insert($notrigger = 0, $noerrorifdiscountalreadylinked = 0)
{
global $langs, $user, $conf;
$error = 0;
- $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
+ $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
- dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
+ dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
// Clean parameters
$this->desc = trim($this->desc);
@@ -4983,7 +4983,7 @@ class FactureLigne extends CommonInvoiceLine
$sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
$sql .= " '".$this->db->escape($this->desc)."',";
$sql .= " ".price2num($this->qty).",";
- $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
+ $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
$sql .= " ".price2num($this->tva_tx).",";
$sql .= " ".price2num($this->localtax1_tx).",";
$sql .= " ".price2num($this->localtax2_tx).",";
@@ -5028,14 +5028,14 @@ class FactureLigne extends CommonInvoiceLine
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet');
$this->rowid = $this->id; // For backward compatibility
- if (!$error)
- {
- $result = $this->insertExtraFields();
- if ($result < 0)
- {
- $error++;
- }
- }
+ if (!$error)
+ {
+ $result = $this->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
// Si fk_remise_except defini, on lie la remise a la facture
// ce qui la flague comme "consommee".
@@ -5048,16 +5048,16 @@ class FactureLigne extends CommonInvoiceLine
// Check if discount was found
if ($result > 0)
{
- // Check if discount not already affected to another invoice
+ // Check if discount not already affected to another invoice
if ($discount->fk_facture_line > 0)
{
- if (empty($noerrorifdiscountalreadylinked))
- {
- $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id);
- dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
- $this->db->rollback();
- return -3;
- }
+ if (empty($noerrorifdiscountalreadylinked))
+ {
+ $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id);
+ dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
+ $this->db->rollback();
+ return -3;
+ }
} else {
$result = $discount->link_to_invoice($this->rowid, 0);
if ($result < 0)
@@ -5084,14 +5084,14 @@ class FactureLigne extends CommonInvoiceLine
if (!$notrigger)
{
- // Call trigger
- $result = $this->call_trigger('LINEBILL_INSERT', $user);
- if ($result < 0)
- {
+ // Call trigger
+ $result = $this->call_trigger('LINEBILL_INSERT', $user);
+ if ($result < 0)
+ {
$this->db->rollback();
return -2;
}
- // End call triggers
+ // End call triggers
}
$this->db->commit();
@@ -5110,7 +5110,7 @@ class FactureLigne extends CommonInvoiceLine
* @param int $notrigger Disable triggers
* @return int <0 if KO, >0 if OK
*/
- public function update($user = '', $notrigger = 0)
+ public function update($user = '', $notrigger = 0)
{
global $user, $conf;
@@ -5157,35 +5157,35 @@ class FactureLigne extends CommonInvoiceLine
$this->db->begin();
- // Mise a jour ligne en base
- $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
- $sql .= " description='".$this->db->escape($this->desc)."'";
- $sql .= " ref_ext='".$this->db->escape($this->ref_ext)."'";
- $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
- $sql .= ", subprice=".price2num($this->subprice)."";
- $sql .= ", remise_percent=".price2num($this->remise_percent)."";
- if ($this->fk_remise_except) $sql .= ", fk_remise_except=".$this->fk_remise_except;
- else $sql .= ", fk_remise_except=null";
+ // Mise a jour ligne en base
+ $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
+ $sql .= " description='".$this->db->escape($this->desc)."'";
+ $sql .= " ref_ext='".$this->db->escape($this->ref_ext)."'";
+ $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
+ $sql .= ", subprice=".price2num($this->subprice)."";
+ $sql .= ", remise_percent=".price2num($this->remise_percent)."";
+ if ($this->fk_remise_except) $sql .= ", fk_remise_except=".$this->fk_remise_except;
+ else $sql .= ", fk_remise_except=null";
$sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->db->escape($this->vat_src_code))."'";
- $sql .= ", tva_tx=".price2num($this->tva_tx)."";
- $sql .= ", localtax1_tx=".price2num($this->localtax1_tx)."";
- $sql .= ", localtax2_tx=".price2num($this->localtax2_tx)."";
+ $sql .= ", tva_tx=".price2num($this->tva_tx)."";
+ $sql .= ", localtax1_tx=".price2num($this->localtax1_tx)."";
+ $sql .= ", localtax2_tx=".price2num($this->localtax2_tx)."";
$sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
$sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
- $sql .= ", qty=".price2num($this->qty);
- $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
- $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
- $sql .= ", product_type=".$this->product_type;
- $sql .= ", info_bits='".$this->db->escape($this->info_bits)."'";
- $sql .= ", special_code='".$this->db->escape($this->special_code)."'";
- if (empty($this->skip_update_total))
- {
- $sql .= ", total_ht=".price2num($this->total_ht);
- $sql .= ", total_tva=".price2num($this->total_tva);
- $sql .= ", total_ttc=".price2num($this->total_ttc);
- $sql .= ", total_localtax1=".price2num($this->total_localtax1);
- $sql .= ", total_localtax2=".price2num($this->total_localtax2);
- }
+ $sql .= ", qty=".price2num($this->qty);
+ $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
+ $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
+ $sql .= ", product_type=".$this->product_type;
+ $sql .= ", info_bits='".$this->db->escape($this->info_bits)."'";
+ $sql .= ", special_code='".$this->db->escape($this->special_code)."'";
+ if (empty($this->skip_update_total))
+ {
+ $sql .= ", total_ht=".price2num($this->total_ht);
+ $sql .= ", total_tva=".price2num($this->total_tva);
+ $sql .= ", total_ttc=".price2num($this->total_ttc);
+ $sql .= ", total_localtax1=".price2num($this->total_localtax1);
+ $sql .= ", total_localtax2=".price2num($this->total_localtax2);
+ }
$sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null");
$sql .= ", buy_price_ht='".price2num($this->pa_ht)."'";
$sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
@@ -5196,9 +5196,9 @@ class FactureLigne extends CommonInvoiceLine
// Multicurrency
$sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
- $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
- $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
- $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
+ $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
+ $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
+ $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql .= " WHERE rowid = ".$this->rowid;
@@ -5206,26 +5206,26 @@ class FactureLigne extends CommonInvoiceLine
$resql = $this->db->query($sql);
if ($resql)
{
- if (!$error)
- {
- $this->id = $this->rowid;
- $result = $this->insertExtraFields();
- if ($result < 0)
- {
- $error++;
- }
- }
+ if (!$error)
+ {
+ $this->id = $this->rowid;
+ $result = $this->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
if (!$error && !$notrigger)
{
- // Call trigger
- $result = $this->call_trigger('LINEBILL_UPDATE', $user);
- if ($result < 0)
+ // Call trigger
+ $result = $this->call_trigger('LINEBILL_UPDATE', $user);
+ if ($result < 0)
{
$this->db->rollback();
return -2;
}
- // End call triggers
+ // End call triggers
}
$this->db->commit();
return 1;
@@ -5239,10 +5239,10 @@ class FactureLigne extends CommonInvoiceLine
/**
* Delete line in database
* TODO Add param User $user and notrigger (see skeleton)
- *
+ *
* @return int <0 if KO, >0 if OK
*/
- public function delete()
+ public function delete()
{
global $user;
@@ -5257,13 +5257,13 @@ class FactureLigne extends CommonInvoiceLine
}
// End call triggers
- // extrafields
- $result = $this->deleteExtraFields();
- if ($result < 0)
- {
- $this->db->rollback();
- return -1;
- }
+ // extrafields
+ $result = $this->deleteExtraFields();
+ if ($result < 0)
+ {
+ $this->db->rollback();
+ return -1;
+ }
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
@@ -5278,16 +5278,16 @@ class FactureLigne extends CommonInvoiceLine
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
- * Update DB line fields total_xxx
+ * Update DB line fields total_xxx
* Used by migration
*
* @return int <0 if KO, >0 if OK
*/
- public function update_total()
+ public function update_total()
{
- // phpcs:enable
+ // phpcs:enable
$this->db->begin();
dol_syslog(get_class($this)."::update_total", LOG_DEBUG);
@@ -5318,7 +5318,7 @@ class FactureLigne extends CommonInvoiceLine
}
}
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
+ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Returns situation_percent of the previous line.
* Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line.
@@ -5327,14 +5327,14 @@ class FactureLigne extends CommonInvoiceLine
* @param bool $include_credit_note Include credit note or not
* @return int >= 0
*/
- public function get_prev_progress($invoiceid, $include_credit_note = true)
+ public function get_prev_progress($invoiceid, $include_credit_note = true)
{
- // phpcs:enable
+ // phpcs:enable
global $invoicecache;
if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
return 0;
} else {
- // If invoice is not a situation invoice, this->fk_prev_id is used for something else
+ // If invoice is not a situation invoice, this->fk_prev_id is used for something else
if (!isset($invoicecache[$invoiceid])) {
$invoicecache[$invoiceid] = new Facture($this->db);
$invoicecache[$invoiceid]->fetch($invoiceid);
@@ -5349,20 +5349,20 @@ class FactureLigne extends CommonInvoiceLine
$returnPercent = floatval($res['situation_percent']);
if ($include_credit_note) {
- $sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd';
- $sql .= ' JOIN '.MAIN_DB_PREFIX.'facture f ON (f.rowid = fd.fk_facture) ';
- $sql .= ' WHERE fd.fk_prev_id ='.$this->fk_prev_id;
- $sql .= ' AND f.situation_cycle_ref = '.$invoicecache[$invoiceid]->situation_cycle_ref; // Prevent cycle outed
- $sql .= ' AND f.type = '.Facture::TYPE_CREDIT_NOTE;
+ $sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd';
+ $sql .= ' JOIN '.MAIN_DB_PREFIX.'facture f ON (f.rowid = fd.fk_facture) ';
+ $sql .= ' WHERE fd.fk_prev_id ='.$this->fk_prev_id;
+ $sql .= ' AND f.situation_cycle_ref = '.$invoicecache[$invoiceid]->situation_cycle_ref; // Prevent cycle outed
+ $sql .= ' AND f.type = '.Facture::TYPE_CREDIT_NOTE;
- $res = $this->db->query($sql);
- if ($res) {
- while ($obj = $this->db->fetch_object($res)) {
- $returnPercent = $returnPercent + floatval($obj->situation_percent);
- }
- } else {
- dol_print_error($this->db);
- }
+ $res = $this->db->query($sql);
+ if ($res) {
+ while ($obj = $this->db->fetch_object($res)) {
+ $returnPercent = $returnPercent + floatval($obj->situation_percent);
+ }
+ } else {
+ dol_print_error($this->db);
+ }
}
return $returnPercent;
diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index 0331861ea03..606e4e626b0 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -177,10 +177,10 @@ if (empty($reshook))
if ($canvas) $object->canvas = $canvas;
$object->entity = (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
- $object->socid = GETPOST("socid", 'int');
+ $object->socid = GETPOST("socid", 'int');
$object->lastname = GETPOST("lastname", 'alpha');
$object->firstname = GETPOST("firstname", 'alpha');
- $object->civility_code = GETPOST("civility_code", 'alpha');
+ $object->civility_code = GETPOST("civility_code", 'alpha');
$object->poste = GETPOST("poste", 'alpha');
$object->address = GETPOST("address", 'alpha');
$object->zip = GETPOST("zipcode", 'alpha');
@@ -1355,7 +1355,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$object->fetch_thirdparty();
- if (! empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
+ if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3)
{
print '
';
@@ -1368,11 +1368,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '
';
print '
';
if ($action == 'editlevel') {
- $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
+ $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
} else {
print $object->getLibProspLevel();
}
@@ -1381,13 +1381,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Status of prospection
$object->loadCacheOfProspStatus();
- print ' | | ' . $langs->trans("StatusProsp") . ' | ' . $object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
+ print ' |
| '.$langs->trans("StatusProsp").' | '.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
print ' ';
print ' |
';
diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php
index a474df3b910..1772f94abfb 100644
--- a/htdocs/contact/list.php
+++ b/htdocs/contact/list.php
@@ -158,8 +158,8 @@ $fieldstosearchall = array(
'p.phone_perso'=>"PhonePerso",
'p.phone_mobile'=>"PhoneMobile",
'p.fax'=>"Fax",
- 'p.note_public'=>"NotePublic",
- 'p.note_private'=>"NotePrivate",
+ 'p.note_public'=>"NotePublic",
+ 'p.note_private'=>"NotePrivate",
);
// Definition of fields for list
@@ -541,7 +541,7 @@ $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
$newcardbutton = '';
if ($user->rights->societe->contact->creer)
{
- $newcardbutton .= dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create');
+ $newcardbutton .= dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create');
}
print '