@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | if (! $sortorder) $sortorder="ASC"; |
| 47 | 47 | if (! $sortfield) |
| 48 | 48 | { |
| 49 | - if ($agentid > 0) |
|
| 50 | - $sortfield="s.nom"; |
|
| 51 | - else |
|
| 52 | - $sortfield="u.lastname"; |
|
| 49 | + if ($agentid > 0) |
|
| 50 | + $sortfield="s.nom"; |
|
| 51 | + else |
|
| 52 | + $sortfield="u.lastname"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $startdate=$enddate=''; |
| 56 | 56 | |
| 57 | 57 | if (!empty($_POST['startdatemonth'])) |
| 58 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 58 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 59 | 59 | if (!empty($_POST['enddatemonth'])) |
| 60 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 60 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 61 | 61 | |
| 62 | 62 | // Security check |
| 63 | 63 | if ($user->rights->margins->read->all) { |
| 64 | - $agentid = GETPOST('agentid', 'int'); |
|
| 64 | + $agentid = GETPOST('agentid', 'int'); |
|
| 65 | 65 | } else { |
| 66 | - $agentid = $user->id; |
|
| 66 | + $agentid = $user->id; |
|
| 67 | 67 | } |
| 68 | 68 | $result=restrictedArea($user,'margins'); |
| 69 | 69 | |
@@ -143,22 +143,22 @@ discard block |
||
| 143 | 143 | $sql.= " AND sc.fk_soc = f.fk_soc"; |
| 144 | 144 | $sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
| 145 | 145 | if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
| 146 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
|
| 146 | + $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
|
| 147 | 147 | else |
| 148 | - $sql .= " AND sc.fk_user = u.rowid"; |
|
| 148 | + $sql .= " AND sc.fk_user = u.rowid"; |
|
| 149 | 149 | $sql.= " AND f.fk_statut > 0"; |
| 150 | 150 | $sql.= ' AND s.entity IN ('.getEntity('societe').')'; |
| 151 | 151 | $sql.= " AND d.fk_facture = f.rowid"; |
| 152 | 152 | if ($agentid > 0) { |
| 153 | - if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 154 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
| 155 | - else |
|
| 156 | - $sql .= " AND sc.fk_user = ".$agentid; |
|
| 153 | + if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 154 | + $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
| 155 | + else |
|
| 156 | + $sql .= " AND sc.fk_user = ".$agentid; |
|
| 157 | 157 | } |
| 158 | 158 | if (!empty($startdate)) |
| 159 | - $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 159 | + $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 160 | 160 | if (!empty($enddate)) |
| 161 | - $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 161 | + $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 162 | 162 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 163 | 163 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
| 164 | 164 | if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; |
@@ -176,87 +176,87 @@ discard block |
||
| 176 | 176 | $result = $db->query($sql); |
| 177 | 177 | if ($result) |
| 178 | 178 | { |
| 179 | - $num = $db->num_rows($result); |
|
| 180 | - |
|
| 181 | - print '<br>'; |
|
| 182 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
| 183 | - |
|
| 184 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 185 | - $labelcostprice='BuyingPrice'; |
|
| 186 | - else // value is 'costprice' or 'pmp' |
|
| 187 | - $labelcostprice='CostPrice'; |
|
| 188 | - |
|
| 189 | - $i = 0; |
|
| 190 | - print "<table class=\"noborder\" width=\"100%\">"; |
|
| 191 | - |
|
| 192 | - print '<tr class="liste_titre">'; |
|
| 193 | - if ($agentid > 0) |
|
| 194 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 195 | - else |
|
| 196 | - print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 197 | - |
|
| 198 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 199 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 200 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 201 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 202 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 203 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 204 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 205 | - print "</tr>\n"; |
|
| 206 | - |
|
| 207 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 208 | - |
|
| 209 | - if ($num > 0) |
|
| 210 | - { |
|
| 211 | - |
|
| 212 | - while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 213 | - { |
|
| 214 | - $objp = $db->fetch_object($result); |
|
| 215 | - |
|
| 216 | - $pa = $objp->buying_price; |
|
| 217 | - $pv = $objp->selling_price; |
|
| 218 | - $marge = $objp->marge; |
|
| 219 | - |
|
| 220 | - if ($marge < 0) |
|
| 221 | - { |
|
| 222 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 223 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 224 | - } |
|
| 225 | - else |
|
| 226 | - { |
|
| 227 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 228 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - print '<tr class="oddeven">'; |
|
| 232 | - if ($agentid > 0) { |
|
| 233 | - $companystatic->id=$objp->socid; |
|
| 234 | - $companystatic->name=$objp->name; |
|
| 235 | - $companystatic->client=$objp->client; |
|
| 236 | - print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n"; |
|
| 237 | - } |
|
| 238 | - else { |
|
| 239 | - $userstatic->fetch($objp->agent); |
|
| 240 | - print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
| 244 | - print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
| 245 | - print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 246 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 247 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 248 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 249 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 250 | - print "</tr>\n"; |
|
| 251 | - |
|
| 252 | - $i++; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - print "</table>"; |
|
| 179 | + $num = $db->num_rows($result); |
|
| 180 | + |
|
| 181 | + print '<br>'; |
|
| 182 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
| 183 | + |
|
| 184 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 185 | + $labelcostprice='BuyingPrice'; |
|
| 186 | + else // value is 'costprice' or 'pmp' |
|
| 187 | + $labelcostprice='CostPrice'; |
|
| 188 | + |
|
| 189 | + $i = 0; |
|
| 190 | + print "<table class=\"noborder\" width=\"100%\">"; |
|
| 191 | + |
|
| 192 | + print '<tr class="liste_titre">'; |
|
| 193 | + if ($agentid > 0) |
|
| 194 | + print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 195 | + else |
|
| 196 | + print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 197 | + |
|
| 198 | + print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 199 | + print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 200 | + print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 201 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 202 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 203 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 204 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 205 | + print "</tr>\n"; |
|
| 206 | + |
|
| 207 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 208 | + |
|
| 209 | + if ($num > 0) |
|
| 210 | + { |
|
| 211 | + |
|
| 212 | + while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 213 | + { |
|
| 214 | + $objp = $db->fetch_object($result); |
|
| 215 | + |
|
| 216 | + $pa = $objp->buying_price; |
|
| 217 | + $pv = $objp->selling_price; |
|
| 218 | + $marge = $objp->marge; |
|
| 219 | + |
|
| 220 | + if ($marge < 0) |
|
| 221 | + { |
|
| 222 | + $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 223 | + $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 224 | + } |
|
| 225 | + else |
|
| 226 | + { |
|
| 227 | + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 228 | + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + print '<tr class="oddeven">'; |
|
| 232 | + if ($agentid > 0) { |
|
| 233 | + $companystatic->id=$objp->socid; |
|
| 234 | + $companystatic->name=$objp->name; |
|
| 235 | + $companystatic->client=$objp->client; |
|
| 236 | + print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n"; |
|
| 237 | + } |
|
| 238 | + else { |
|
| 239 | + $userstatic->fetch($objp->agent); |
|
| 240 | + print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
| 244 | + print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
| 245 | + print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 246 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 247 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 248 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 249 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 250 | + print "</tr>\n"; |
|
| 251 | + |
|
| 252 | + $i++; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + print "</table>"; |
|
| 256 | 256 | } |
| 257 | 257 | else |
| 258 | 258 | { |
| 259 | - dol_print_error($db); |
|
| 259 | + dol_print_error($db); |
|
| 260 | 260 | } |
| 261 | 261 | $db->free($result); |
| 262 | 262 | |
@@ -43,21 +43,26 @@ discard block |
||
| 43 | 43 | $offset = $limit * $page; |
| 44 | 44 | $pageprev = $page - 1; |
| 45 | 45 | $pagenext = $page + 1; |
| 46 | -if (! $sortorder) $sortorder="ASC"; |
|
| 46 | +if (! $sortorder) { |
|
| 47 | + $sortorder="ASC"; |
|
| 48 | +} |
|
| 47 | 49 | if (! $sortfield) |
| 48 | 50 | { |
| 49 | - if ($agentid > 0) |
|
| 50 | - $sortfield="s.nom"; |
|
| 51 | - else |
|
| 52 | - $sortfield="u.lastname"; |
|
| 53 | -} |
|
| 51 | + if ($agentid > 0) { |
|
| 52 | + $sortfield="s.nom"; |
|
| 53 | + } else { |
|
| 54 | + $sortfield="u.lastname"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 54 | 57 | |
| 55 | 58 | $startdate=$enddate=''; |
| 56 | 59 | |
| 57 | -if (!empty($_POST['startdatemonth'])) |
|
| 60 | +if (!empty($_POST['startdatemonth'])) { |
|
| 58 | 61 | $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
| 59 | -if (!empty($_POST['enddatemonth'])) |
|
| 62 | +} |
|
| 63 | +if (!empty($_POST['enddatemonth'])) { |
|
| 60 | 64 | $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
| 65 | +} |
|
| 61 | 66 | |
| 62 | 67 | // Security check |
| 63 | 68 | if ($user->rights->margins->read->all) { |
@@ -126,7 +131,9 @@ discard block |
||
| 126 | 131 | print '</form>'; |
| 127 | 132 | |
| 128 | 133 | $sql = "SELECT"; |
| 129 | -if ($agentid > 0) $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
|
| 134 | +if ($agentid > 0) { |
|
| 135 | + $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
|
| 136 | +} |
|
| 130 | 137 | $sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,"; |
| 131 | 138 | $sql.= " sum(d.total_ht) as selling_price,"; |
| 132 | 139 | // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this) |
@@ -142,27 +149,36 @@ discard block |
||
| 142 | 149 | $sql.= ' AND f.entity IN ('.getEntity('invoice').')'; |
| 143 | 150 | $sql.= " AND sc.fk_soc = f.fk_soc"; |
| 144 | 151 | $sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
| 145 | -if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 152 | +if (! empty($conf->global->AGENT_CONTACT_TYPE)) { |
|
| 146 | 153 | $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
| 147 | -else |
|
| 154 | +} else { |
|
| 148 | 155 | $sql .= " AND sc.fk_user = u.rowid"; |
| 156 | +} |
|
| 149 | 157 | $sql.= " AND f.fk_statut > 0"; |
| 150 | 158 | $sql.= ' AND s.entity IN ('.getEntity('societe').')'; |
| 151 | 159 | $sql.= " AND d.fk_facture = f.rowid"; |
| 152 | 160 | if ($agentid > 0) { |
| 153 | - if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 154 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
| 155 | - else |
|
| 156 | - $sql .= " AND sc.fk_user = ".$agentid; |
|
| 157 | -} |
|
| 158 | -if (!empty($startdate)) |
|
| 161 | + if (! empty($conf->global->AGENT_CONTACT_TYPE)) { |
|
| 162 | + $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
| 163 | + } else { |
|
| 164 | + $sql .= " AND sc.fk_user = ".$agentid; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | +if (!empty($startdate)) { |
|
| 159 | 168 | $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
| 160 | -if (!empty($enddate)) |
|
| 169 | +} |
|
| 170 | +if (!empty($enddate)) { |
|
| 161 | 171 | $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
| 172 | +} |
|
| 162 | 173 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 163 | -if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
|
| 164 | -if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; |
|
| 165 | -else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname"; |
|
| 174 | +if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) { |
|
| 175 | + $sql .= " AND d.buy_price_ht <> 0"; |
|
| 176 | +} |
|
| 177 | +if ($agentid > 0) { |
|
| 178 | + $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; |
|
| 179 | +} else { |
|
| 180 | + $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname"; |
|
| 181 | +} |
|
| 166 | 182 | $sql.=$db->order($sortfield,$sortorder); |
| 167 | 183 | // TODO: calculate total to display then restore pagination |
| 168 | 184 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
@@ -181,27 +197,32 @@ discard block |
||
| 181 | 197 | print '<br>'; |
| 182 | 198 | print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
| 183 | 199 | |
| 184 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 185 | - $labelcostprice='BuyingPrice'; |
|
| 186 | - else // value is 'costprice' or 'pmp' |
|
| 200 | + if ($conf->global->MARGIN_TYPE == "1") { |
|
| 201 | + $labelcostprice='BuyingPrice'; |
|
| 202 | + } else { |
|
| 203 | + // value is 'costprice' or 'pmp' |
|
| 187 | 204 | $labelcostprice='CostPrice'; |
| 205 | + } |
|
| 188 | 206 | |
| 189 | 207 | $i = 0; |
| 190 | 208 | print "<table class=\"noborder\" width=\"100%\">"; |
| 191 | 209 | |
| 192 | 210 | print '<tr class="liste_titre">'; |
| 193 | - if ($agentid > 0) |
|
| 194 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 195 | - else |
|
| 196 | - print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 211 | + if ($agentid > 0) { |
|
| 212 | + print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 213 | + } else { |
|
| 214 | + print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
| 199 | 218 | print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
| 200 | 219 | print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
| 201 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 202 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 203 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 204 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 220 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 221 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 222 | + } |
|
| 223 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 224 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 225 | + } |
|
| 205 | 226 | print "</tr>\n"; |
| 206 | 227 | |
| 207 | 228 | $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
@@ -221,8 +242,7 @@ discard block |
||
| 221 | 242 | { |
| 222 | 243 | $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
| 223 | 244 | $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
| 224 | - } |
|
| 225 | - else |
|
| 245 | + } else |
|
| 226 | 246 | { |
| 227 | 247 | $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
| 228 | 248 | $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
@@ -234,8 +254,7 @@ discard block |
||
| 234 | 254 | $companystatic->name=$objp->name; |
| 235 | 255 | $companystatic->client=$objp->client; |
| 236 | 256 | print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n"; |
| 237 | - } |
|
| 238 | - else { |
|
| 257 | + } else { |
|
| 239 | 258 | $userstatic->fetch($objp->agent); |
| 240 | 259 | print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n"; |
| 241 | 260 | } |
@@ -243,18 +262,19 @@ discard block |
||
| 243 | 262 | print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
| 244 | 263 | print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
| 245 | 264 | print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
| 246 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 247 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 248 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 249 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 265 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 266 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 267 | + } |
|
| 268 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 269 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 270 | + } |
|
| 250 | 271 | print "</tr>\n"; |
| 251 | 272 | |
| 252 | 273 | $i++; |
| 253 | 274 | } |
| 254 | 275 | } |
| 255 | 276 | print "</table>"; |
| 256 | -} |
|
| 257 | -else |
|
| 277 | +} else |
|
| 258 | 278 | { |
| 259 | 279 | dol_print_error($db); |
| 260 | 280 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
| 28 | 28 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
| 29 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
| 29 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
| 30 | 30 | |
| 31 | 31 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
| 32 | 32 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
@@ -39,29 +39,29 @@ discard block |
||
| 39 | 39 | $mesg = ''; |
| 40 | 40 | |
| 41 | 41 | // Load variable for pagination |
| 42 | -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
|
| 43 | -$sortfield = GETPOST('sortfield','alpha'); |
|
| 44 | -$sortorder = GETPOST('sortorder','alpha'); |
|
| 45 | -$page = GETPOST('page','int'); |
|
| 42 | +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; |
|
| 43 | +$sortfield = GETPOST('sortfield', 'alpha'); |
|
| 44 | +$sortorder = GETPOST('sortorder', 'alpha'); |
|
| 45 | +$page = GETPOST('page', 'int'); |
|
| 46 | 46 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
| 47 | 47 | $offset = $limit * $page; |
| 48 | 48 | $pageprev = $page - 1; |
| 49 | 49 | $pagenext = $page + 1; |
| 50 | -if (! $sortorder) $sortorder="ASC"; |
|
| 51 | -if (! $sortfield) |
|
| 50 | +if (!$sortorder) $sortorder = "ASC"; |
|
| 51 | +if (!$sortfield) |
|
| 52 | 52 | { |
| 53 | 53 | if ($agentid > 0) |
| 54 | - $sortfield="s.nom"; |
|
| 54 | + $sortfield = "s.nom"; |
|
| 55 | 55 | else |
| 56 | - $sortfield="u.lastname"; |
|
| 56 | + $sortfield = "u.lastname"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | -$startdate=$enddate=''; |
|
| 59 | +$startdate = $enddate = ''; |
|
| 60 | 60 | |
| 61 | 61 | if (!empty($_POST['startdatemonth'])) |
| 62 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 62 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 63 | 63 | if (!empty($_POST['enddatemonth'])) |
| 64 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 64 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 65 | 65 | |
| 66 | 66 | // Security check |
| 67 | 67 | if ($user->rights->margins->read->all) { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } else { |
| 70 | 70 | $agentid = $user->id; |
| 71 | 71 | } |
| 72 | -$result=restrictedArea($user,'margins'); |
|
| 72 | +$result = restrictedArea($user, 'margins'); |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | /* |
@@ -86,19 +86,19 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $userstatic = new User($db); |
| 88 | 88 | $companystatic = new Societe($db); |
| 89 | -$invoicestatic=new Facture($db); |
|
| 89 | +$invoicestatic = new Facture($db); |
|
| 90 | 90 | |
| 91 | 91 | $form = new Form($db); |
| 92 | 92 | |
| 93 | -llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Agents")); |
|
| 93 | +llxHeader('', $langs->trans("Margins").' - '.$langs->trans("Agents")); |
|
| 94 | 94 | |
| 95 | -$text=$langs->trans("Margins"); |
|
| 95 | +$text = $langs->trans("Margins"); |
|
| 96 | 96 | //print load_fiche_titre($text); |
| 97 | 97 | |
| 98 | 98 | // Show tabs |
| 99 | -$head=marges_prepare_head($user); |
|
| 100 | -$titre=$langs->trans("Margins"); |
|
| 101 | -$picto='margin'; |
|
| 99 | +$head = marges_prepare_head($user); |
|
| 100 | +$titre = $langs->trans("Margins"); |
|
| 101 | +$picto = 'margin'; |
|
| 102 | 102 | |
| 103 | 103 | print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">'; |
| 104 | 104 | |
@@ -130,44 +130,44 @@ discard block |
||
| 130 | 130 | print '</form>'; |
| 131 | 131 | |
| 132 | 132 | $sql = "SELECT"; |
| 133 | -if ($agentid > 0) $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
|
| 134 | -$sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,"; |
|
| 135 | -$sql.= " sum(d.total_ht) as selling_price,"; |
|
| 133 | +if ($agentid > 0) $sql .= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
|
| 134 | +$sql .= " u.rowid as agent, u.login, u.lastname, u.firstname,"; |
|
| 135 | +$sql .= " sum(d.total_ht) as selling_price,"; |
|
| 136 | 136 | // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this) |
| 137 | -$sql.= " sum(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,"; |
|
| 138 | -$sql.= " sum(".$db->ifsql('d.total_ht < 0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge" ; |
|
| 139 | -$sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 140 | -$sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 141 | -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE); |
|
| 142 | -$sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 143 | -$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 144 | -$sql.= ", ".MAIN_DB_PREFIX."user as u"; |
|
| 145 | -$sql.= " WHERE f.fk_soc = s.rowid"; |
|
| 146 | -$sql.= ' AND f.entity IN ('.getEntity('invoice').')'; |
|
| 147 | -$sql.= " AND sc.fk_soc = f.fk_soc"; |
|
| 148 | -$sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
|
| 149 | -if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 150 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
|
| 137 | +$sql .= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; |
|
| 138 | +$sql .= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge"; |
|
| 139 | +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 140 | +$sql .= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 141 | +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE) ?-1 : $conf->global->AGENT_CONTACT_TYPE); |
|
| 142 | +$sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 143 | +$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 144 | +$sql .= ", ".MAIN_DB_PREFIX."user as u"; |
|
| 145 | +$sql .= " WHERE f.fk_soc = s.rowid"; |
|
| 146 | +$sql .= ' AND f.entity IN ('.getEntity('invoice').')'; |
|
| 147 | +$sql .= " AND sc.fk_soc = f.fk_soc"; |
|
| 148 | +$sql .= " AND (d.product_type = 0 OR d.product_type = 1)"; |
|
| 149 | +if (!empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 150 | + $sql .= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
|
| 151 | 151 | else |
| 152 | 152 | $sql .= " AND sc.fk_user = u.rowid"; |
| 153 | -$sql.= " AND f.fk_statut > 0"; |
|
| 154 | -$sql.= ' AND s.entity IN ('.getEntity('societe').')'; |
|
| 155 | -$sql.= " AND d.fk_facture = f.rowid"; |
|
| 153 | +$sql .= " AND f.fk_statut > 0"; |
|
| 154 | +$sql .= ' AND s.entity IN ('.getEntity('societe').')'; |
|
| 155 | +$sql .= " AND d.fk_facture = f.rowid"; |
|
| 156 | 156 | if ($agentid > 0) { |
| 157 | - if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 158 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
| 157 | + if (!empty($conf->global->AGENT_CONTACT_TYPE)) |
|
| 158 | + $sql .= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
| 159 | 159 | else |
| 160 | 160 | $sql .= " AND sc.fk_user = ".$agentid; |
| 161 | 161 | } |
| 162 | 162 | if (!empty($startdate)) |
| 163 | - $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 163 | + $sql .= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 164 | 164 | if (!empty($enddate)) |
| 165 | - $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 165 | + $sql .= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 166 | 166 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 167 | 167 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
| 168 | -if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; |
|
| 169 | -else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname"; |
|
| 170 | -$sql.=$db->order($sortfield,$sortorder); |
|
| 168 | +if ($agentid > 0) $sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; |
|
| 169 | +else $sql .= " GROUP BY u.rowid, u.login, u.lastname, u.firstname"; |
|
| 170 | +$sql .= $db->order($sortfield, $sortorder); |
|
| 171 | 171 | // TODO: calculate total to display then restore pagination |
| 172 | 172 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
| 173 | 173 | |
@@ -186,29 +186,29 @@ discard block |
||
| 186 | 186 | print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
| 187 | 187 | |
| 188 | 188 | if ($conf->global->MARGIN_TYPE == "1") |
| 189 | - $labelcostprice='BuyingPrice'; |
|
| 189 | + $labelcostprice = 'BuyingPrice'; |
|
| 190 | 190 | else // value is 'costprice' or 'pmp' |
| 191 | - $labelcostprice='CostPrice'; |
|
| 191 | + $labelcostprice = 'CostPrice'; |
|
| 192 | 192 | |
| 193 | 193 | $i = 0; |
| 194 | 194 | print "<table class=\"noborder\" width=\"100%\">"; |
| 195 | 195 | |
| 196 | 196 | print '<tr class="liste_titre">'; |
| 197 | 197 | if ($agentid > 0) |
| 198 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 198 | + print_liste_field_titre("Customer", $_SERVER["PHP_SELF"], "s.nom", "", "&agentid=".$agentid, '', $sortfield, $sortorder); |
|
| 199 | 199 | else |
| 200 | - print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
| 201 | - |
|
| 202 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 203 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 204 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 205 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 206 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 207 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 208 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
| 200 | + print_liste_field_titre("SalesRepresentative", $_SERVER["PHP_SELF"], "u.lastname", "", "&agentid=".$agentid, '', $sortfield, $sortorder); |
|
| 201 | + |
|
| 202 | + print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&agentid=".$agentid, 'align="right"', $sortfield, $sortorder); |
|
| 203 | + print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&agentid=".$agentid, 'align="right"', $sortfield, $sortorder); |
|
| 204 | + print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&agentid=".$agentid, 'align="right"', $sortfield, $sortorder); |
|
| 205 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 206 | + print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&agentid=".$agentid, 'align="right"', $sortfield, $sortorder); |
|
| 207 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 208 | + print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&agentid=".$agentid, 'align="right"', $sortfield, $sortorder); |
|
| 209 | 209 | print "</tr>\n"; |
| 210 | 210 | |
| 211 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 211 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 212 | 212 | |
| 213 | 213 | if ($num > 0) |
| 214 | 214 | { |
@@ -223,34 +223,34 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | if ($marge < 0) |
| 225 | 225 | { |
| 226 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 227 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 226 | + $marginRate = ($pa != 0) ?-1 * (100 * $marge / $pa) : ''; |
|
| 227 | + $markRate = ($pv != 0) ?-1 * (100 * $marge / $pv) : ''; |
|
| 228 | 228 | } |
| 229 | 229 | else |
| 230 | 230 | { |
| 231 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 232 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 231 | + $marginRate = ($pa != 0) ? (100 * $marge / $pa) : ''; |
|
| 232 | + $markRate = ($pv != 0) ? (100 * $marge / $pv) : ''; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | print '<tr class="oddeven">'; |
| 236 | 236 | if ($agentid > 0) { |
| 237 | - $companystatic->id=$objp->socid; |
|
| 238 | - $companystatic->name=$objp->name; |
|
| 239 | - $companystatic->client=$objp->client; |
|
| 240 | - print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n"; |
|
| 237 | + $companystatic->id = $objp->socid; |
|
| 238 | + $companystatic->name = $objp->name; |
|
| 239 | + $companystatic->client = $objp->client; |
|
| 240 | + print "<td>".$companystatic->getNomUrl(1, 'customer')."</td>\n"; |
|
| 241 | 241 | } |
| 242 | 242 | else { |
| 243 | 243 | $userstatic->fetch($objp->agent); |
| 244 | - print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n"; |
|
| 244 | + print "<td>".$userstatic->getFullName($langs, 0, 0, 0)."</td>\n"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
| 248 | 248 | print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
| 249 | 249 | print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
| 250 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 251 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 252 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 253 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 250 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 251 | + print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 252 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 253 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 254 | 254 | print "</tr>\n"; |
| 255 | 255 | |
| 256 | 256 | $i++; |
@@ -67,32 +67,32 @@ discard block |
||
| 67 | 67 | $result = $object->fetch($id, $ref); |
| 68 | 68 | |
| 69 | 69 | $title = $langs->trans('ProductServiceCard'); |
| 70 | - $helpurl = ''; |
|
| 71 | - $shortlabel = dol_trunc($object->label,16); |
|
| 72 | - if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) |
|
| 73 | - { |
|
| 74 | - $title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card'); |
|
| 75 | - $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; |
|
| 76 | - } |
|
| 77 | - if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) |
|
| 78 | - { |
|
| 79 | - $title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card'); |
|
| 80 | - $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - llxHeader('', $title, $helpurl); |
|
| 84 | - |
|
| 85 | - /* |
|
| 70 | + $helpurl = ''; |
|
| 71 | + $shortlabel = dol_trunc($object->label,16); |
|
| 72 | + if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) |
|
| 73 | + { |
|
| 74 | + $title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card'); |
|
| 75 | + $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; |
|
| 76 | + } |
|
| 77 | + if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) |
|
| 78 | + { |
|
| 79 | + $title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card'); |
|
| 80 | + $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + llxHeader('', $title, $helpurl); |
|
| 84 | + |
|
| 85 | + /* |
|
| 86 | 86 | * En mode visu |
| 87 | 87 | */ |
| 88 | - if ($result > 0) |
|
| 89 | - { |
|
| 90 | - $head=product_prepare_head($object); |
|
| 91 | - $titre=$langs->trans("CardProduct".$object->type); |
|
| 92 | - $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); |
|
| 93 | - dol_fiche_head($head, 'margin', $titre, -1, $picto); |
|
| 88 | + if ($result > 0) |
|
| 89 | + { |
|
| 90 | + $head=product_prepare_head($object); |
|
| 91 | + $titre=$langs->trans("CardProduct".$object->type); |
|
| 92 | + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); |
|
| 93 | + dol_fiche_head($head, 'margin', $titre, -1, $picto); |
|
| 94 | 94 | |
| 95 | - $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
|
| 95 | + $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
|
| 96 | 96 | |
| 97 | 97 | dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref'); |
| 98 | 98 | |
@@ -102,31 +102,31 @@ discard block |
||
| 102 | 102 | print '<div class="underbanner clearboth"></div>'; |
| 103 | 103 | print '<table class="border tableforfield" width="100%">'; |
| 104 | 104 | |
| 105 | - // Total Margin |
|
| 106 | - print '<tr><td class="titlefield">'.$langs->trans("TotalMargin").'</td><td colspan="3">'; |
|
| 107 | - print '<span id="totalMargin"></span>'; // set by jquery (see below) |
|
| 108 | - print '</td></tr>'; |
|
| 105 | + // Total Margin |
|
| 106 | + print '<tr><td class="titlefield">'.$langs->trans("TotalMargin").'</td><td colspan="3">'; |
|
| 107 | + print '<span id="totalMargin"></span>'; // set by jquery (see below) |
|
| 108 | + print '</td></tr>'; |
|
| 109 | 109 | |
| 110 | - // Margin Rate |
|
| 111 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 112 | - print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">'; |
|
| 113 | - print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 114 | - print '</td></tr>'; |
|
| 115 | - } |
|
| 110 | + // Margin Rate |
|
| 111 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 112 | + print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">'; |
|
| 113 | + print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 114 | + print '</td></tr>'; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - // Mark Rate |
|
| 118 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 119 | - print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">'; |
|
| 120 | - print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 121 | - print '</td></tr>'; |
|
| 122 | - } |
|
| 117 | + // Mark Rate |
|
| 118 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 119 | + print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">'; |
|
| 120 | + print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 121 | + print '</td></tr>'; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - print "</table>"; |
|
| 124 | + print "</table>"; |
|
| 125 | 125 | |
| 126 | 126 | print '</div>'; |
| 127 | 127 | print '<div style="clear:both"></div>'; |
| 128 | 128 | |
| 129 | - dol_fiche_end(); |
|
| 129 | + dol_fiche_end(); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | if ($user->rights->facture->lire) { |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | while ($i < $num /*&& $i < $conf->liste_limit*/) { |
| 194 | 194 | $objp = $db->fetch_object($result); |
| 195 | 195 | |
| 196 | - $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; |
|
| 197 | - $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; |
|
| 196 | + $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; |
|
| 197 | + $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; |
|
| 198 | 198 | |
| 199 | 199 | print '<tr class="oddeven">'; |
| 200 | 200 | print '<td>'; |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | print "</td>\n"; |
| 205 | 205 | print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>'; |
| 206 | 206 | print "<td>".$objp->code_client."</td>\n"; |
| 207 | - print "<td align=\"center\">"; |
|
| 208 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 209 | - print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 210 | - print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 211 | - print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n"; |
|
| 212 | - print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 213 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 214 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 215 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 216 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 217 | - print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
|
| 207 | + print "<td align=\"center\">"; |
|
| 208 | + print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 209 | + print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 210 | + print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 211 | + print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n"; |
|
| 212 | + print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 213 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 214 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 215 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 216 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 217 | + print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
|
| 218 | 218 | print "</tr>\n"; |
| 219 | 219 | $i++; |
| 220 | 220 | $cumul_achat += $objp->buying_price; |
@@ -36,7 +36,9 @@ discard block |
||
| 36 | 36 | // Security check |
| 37 | 37 | $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); |
| 38 | 38 | $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); |
| 39 | -if (! empty($user->societe_id)) $socid=$user->societe_id; |
|
| 39 | +if (! empty($user->societe_id)) { |
|
| 40 | + $socid=$user->societe_id; |
|
| 41 | +} |
|
| 40 | 42 | $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); |
| 41 | 43 | |
| 42 | 44 | $object = new Product($db); |
@@ -50,8 +52,12 @@ discard block |
||
| 50 | 52 | $offset = $conf->liste_limit * $page; |
| 51 | 53 | $pageprev = $page - 1; |
| 52 | 54 | $pagenext = $page + 1; |
| 53 | -if (! $sortorder) $sortorder="DESC"; |
|
| 54 | -if (! $sortfield) $sortfield="f.datef"; |
|
| 55 | +if (! $sortorder) { |
|
| 56 | + $sortorder="DESC"; |
|
| 57 | +} |
|
| 58 | +if (! $sortfield) { |
|
| 59 | + $sortfield="f.datef"; |
|
| 60 | +} |
|
| 55 | 61 | |
| 56 | 62 | |
| 57 | 63 | /* |
@@ -133,7 +139,9 @@ discard block |
||
| 133 | 139 | $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,"; |
| 134 | 140 | $sql.= " f.rowid as facid, f.ref, f.total as total_ht,"; |
| 135 | 141 | $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,"; |
| 136 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,"; |
|
| 142 | + if (!$user->rights->societe->client->voir && !$socid) { |
|
| 143 | + $sql.= " sc.fk_soc, sc.fk_user,"; |
|
| 144 | + } |
|
| 137 | 145 | $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive |
| 138 | 146 | $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,"; // not always positive in case of Credit note |
| 139 | 147 | $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note |
@@ -141,18 +149,28 @@ discard block |
||
| 141 | 149 | $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
| 142 | 150 | $sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
| 143 | 151 | $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
| 144 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 152 | + if (!$user->rights->societe->client->voir && !$socid) { |
|
| 153 | + $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 154 | + } |
|
| 145 | 155 | $sql.= " WHERE f.fk_soc = s.rowid"; |
| 146 | 156 | $sql.= " AND f.fk_statut > 0"; |
| 147 | 157 | $sql.= " AND s.entity = ".$conf->entity; |
| 148 | 158 | $sql.= " AND d.fk_facture = f.rowid"; |
| 149 | 159 | $sql.= " AND d.fk_product =".$object->id; |
| 150 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 151 | - if (! empty($socid)) $sql.= " AND f.fk_soc = $socid"; |
|
| 160 | + if (!$user->rights->societe->client->voir && !$socid) { |
|
| 161 | + $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 162 | + } |
|
| 163 | + if (! empty($socid)) { |
|
| 164 | + $sql.= " AND f.fk_soc = $socid"; |
|
| 165 | + } |
|
| 152 | 166 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 153 | - if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
|
| 167 | + if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) { |
|
| 168 | + $sql .= " AND d.buy_price_ht <> 0"; |
|
| 169 | + } |
|
| 154 | 170 | $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; |
| 155 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user"; |
|
| 171 | + if (!$user->rights->societe->client->voir && !$socid) { |
|
| 172 | + $sql.= ", sc.fk_soc, sc.fk_user"; |
|
| 173 | + } |
|
| 156 | 174 | $sql.= $db->order($sortfield,$sortorder); |
| 157 | 175 | // TODO: calculate total to display then restore pagination |
| 158 | 176 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
@@ -177,10 +195,12 @@ discard block |
||
| 177 | 195 | print_liste_field_titre("BuyingPrice",$_SERVER["PHP_SELF"],"buying_price","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
| 178 | 196 | print_liste_field_titre("Qty",$_SERVER["PHP_SELF"],"d.qty","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
| 179 | 197 | print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
| 180 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 181 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 182 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 183 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 198 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 199 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 200 | + } |
|
| 201 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 202 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 203 | + } |
|
| 184 | 204 | print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
| 185 | 205 | print "</tr>\n"; |
| 186 | 206 | |
@@ -210,10 +230,12 @@ discard block |
||
| 210 | 230 | print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
| 211 | 231 | print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n"; |
| 212 | 232 | print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
| 213 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 214 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 215 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 216 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 233 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 234 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 235 | + } |
|
| 236 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 237 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 238 | + } |
|
| 217 | 239 | print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
| 218 | 240 | print "</tr>\n"; |
| 219 | 241 | $i++; |
@@ -230,8 +252,7 @@ discard block |
||
| 230 | 252 | { |
| 231 | 253 | $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
| 232 | 254 | $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
| 233 | - } |
|
| 234 | - else |
|
| 255 | + } else |
|
| 235 | 256 | { |
| 236 | 257 | $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
| 237 | 258 | $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
@@ -242,10 +263,12 @@ discard block |
||
| 242 | 263 | print '<td align="right">'.price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
| 243 | 264 | print '<td align="right">'.price($cumul_qty, null, null, null, null, $rounding)."</td>\n"; |
| 244 | 265 | print '<td align="right">'.price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
| 245 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 246 | - print '<td align="right">'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 247 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 248 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 266 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 267 | + print '<td align="right">'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 268 | + } |
|
| 269 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 270 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 271 | + } |
|
| 249 | 272 | print '<td align="right"> </td>'; |
| 250 | 273 | print "</tr>\n"; |
| 251 | 274 | print "</table>"; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
| 26 | 26 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
| 27 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
| 27 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
| 28 | 28 | require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; |
| 29 | 29 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
| 30 | 30 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
@@ -33,54 +33,54 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | $id = GETPOST('id', 'int'); |
| 35 | 35 | $ref = GETPOST('ref', 'alpha'); |
| 36 | -$action=GETPOST('action','alpha'); |
|
| 37 | -$confirm=GETPOST('confirm','alpha'); |
|
| 36 | +$action = GETPOST('action', 'alpha'); |
|
| 37 | +$confirm = GETPOST('confirm', 'alpha'); |
|
| 38 | 38 | |
| 39 | 39 | // Security check |
| 40 | -$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); |
|
| 41 | -$fieldtype = (! empty($ref) ? 'ref' : 'rowid'); |
|
| 42 | -if (! empty($user->societe_id)) $socid=$user->societe_id; |
|
| 43 | -$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); |
|
| 40 | +$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); |
|
| 41 | +$fieldtype = (!empty($ref) ? 'ref' : 'rowid'); |
|
| 42 | +if (!empty($user->societe_id)) $socid = $user->societe_id; |
|
| 43 | +$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); |
|
| 44 | 44 | |
| 45 | 45 | $object = new Product($db); |
| 46 | 46 | |
| 47 | 47 | $mesg = ''; |
| 48 | 48 | |
| 49 | -$sortfield = GETPOST("sortfield",'alpha'); |
|
| 50 | -$sortorder = GETPOST("sortorder",'alpha'); |
|
| 51 | -$page = GETPOST("page",'int'); |
|
| 49 | +$sortfield = GETPOST("sortfield", 'alpha'); |
|
| 50 | +$sortorder = GETPOST("sortorder", 'alpha'); |
|
| 51 | +$page = GETPOST("page", 'int'); |
|
| 52 | 52 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
| 53 | 53 | $offset = $conf->liste_limit * $page; |
| 54 | 54 | $pageprev = $page - 1; |
| 55 | 55 | $pagenext = $page + 1; |
| 56 | -if (! $sortorder) $sortorder="DESC"; |
|
| 57 | -if (! $sortfield) $sortfield="f.datef"; |
|
| 56 | +if (!$sortorder) $sortorder = "DESC"; |
|
| 57 | +if (!$sortfield) $sortfield = "f.datef"; |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | /* |
| 61 | 61 | * View |
| 62 | 62 | */ |
| 63 | 63 | |
| 64 | -$invoicestatic=new Facture($db); |
|
| 64 | +$invoicestatic = new Facture($db); |
|
| 65 | 65 | |
| 66 | 66 | $form = new Form($db); |
| 67 | 67 | |
| 68 | -if ($id > 0 || ! empty($ref)) |
|
| 68 | +if ($id > 0 || !empty($ref)) |
|
| 69 | 69 | { |
| 70 | 70 | $result = $object->fetch($id, $ref); |
| 71 | 71 | |
| 72 | 72 | $title = $langs->trans('ProductServiceCard'); |
| 73 | 73 | $helpurl = ''; |
| 74 | - $shortlabel = dol_trunc($object->label,16); |
|
| 74 | + $shortlabel = dol_trunc($object->label, 16); |
|
| 75 | 75 | if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) |
| 76 | 76 | { |
| 77 | - $title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card'); |
|
| 78 | - $helpurl='EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; |
|
| 77 | + $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card'); |
|
| 78 | + $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; |
|
| 79 | 79 | } |
| 80 | 80 | if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) |
| 81 | 81 | { |
| 82 | - $title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card'); |
|
| 83 | - $helpurl='EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; |
|
| 82 | + $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card'); |
|
| 83 | + $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | llxHeader('', $title, $helpurl); |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | if ($result > 0) |
| 92 | 92 | { |
| 93 | - $head=product_prepare_head($object); |
|
| 94 | - $titre=$langs->trans("CardProduct".$object->type); |
|
| 95 | - $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); |
|
| 93 | + $head = product_prepare_head($object); |
|
| 94 | + $titre = $langs->trans("CardProduct".$object->type); |
|
| 95 | + $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); |
|
| 96 | 96 | dol_fiche_head($head, 'margin', $titre, -1, $picto); |
| 97 | 97 | |
| 98 | 98 | $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
| 99 | 99 | |
| 100 | - dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref'); |
|
| 100 | + dol_banner_tab($object, 'ref', $linkback, ($user->societe_id ? 0 : 1), 'ref'); |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | print '<div class="fichecenter">'; |
@@ -111,14 +111,14 @@ discard block |
||
| 111 | 111 | print '</td></tr>'; |
| 112 | 112 | |
| 113 | 113 | // Margin Rate |
| 114 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 114 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 115 | 115 | print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">'; |
| 116 | 116 | print '<span id="marginRate"></span>'; // set by jquery (see below) |
| 117 | 117 | print '</td></tr>'; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Mark Rate |
| 121 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 121 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 122 | 122 | print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">'; |
| 123 | 123 | print '<span id="markRate"></span>'; // set by jquery (see below) |
| 124 | 124 | print '</td></tr>'; |
@@ -134,29 +134,29 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | if ($user->rights->facture->lire) { |
| 136 | 136 | $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,"; |
| 137 | - $sql.= " f.rowid as facid, f.ref, f.total as total_ht,"; |
|
| 138 | - $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,"; |
|
| 139 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= " sc.fk_soc, sc.fk_user,"; |
|
| 140 | - $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive |
|
| 141 | - $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,"; // not always positive in case of Credit note |
|
| 142 | - $sql.= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note |
|
| 143 | - $sql.= " IF(f.type = 2, -1, 1) * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge" ; // not always positive in case of Credit note |
|
| 144 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 145 | - $sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 146 | - $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 147 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 148 | - $sql.= " WHERE f.fk_soc = s.rowid"; |
|
| 149 | - $sql.= " AND f.fk_statut > 0"; |
|
| 150 | - $sql.= " AND s.entity = ".$conf->entity; |
|
| 151 | - $sql.= " AND d.fk_facture = f.rowid"; |
|
| 152 | - $sql.= " AND d.fk_product =".$object->id; |
|
| 153 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 154 | - if (! empty($socid)) $sql.= " AND f.fk_soc = $socid"; |
|
| 137 | + $sql .= " f.rowid as facid, f.ref, f.total as total_ht,"; |
|
| 138 | + $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,"; |
|
| 139 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,"; |
|
| 140 | + $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive |
|
| 141 | + $sql .= " IF(f.type = 2, -1, 1) * sum(d.qty) as qty,"; // not always positive in case of Credit note |
|
| 142 | + $sql .= " IF(f.type = 2, -1, 1) * sum(d.qty * d.buy_price_ht) as buying_price,"; // not always positive in case of Credit note |
|
| 143 | + $sql .= " IF(f.type = 2, -1, 1) * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // not always positive in case of Credit note |
|
| 144 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 145 | + $sql .= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 146 | + $sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 147 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 148 | + $sql .= " WHERE f.fk_soc = s.rowid"; |
|
| 149 | + $sql .= " AND f.fk_statut > 0"; |
|
| 150 | + $sql .= " AND s.entity = ".$conf->entity; |
|
| 151 | + $sql .= " AND d.fk_facture = f.rowid"; |
|
| 152 | + $sql .= " AND d.fk_product =".$object->id; |
|
| 153 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
| 154 | + if (!empty($socid)) $sql .= " AND f.fk_soc = $socid"; |
|
| 155 | 155 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 156 | 156 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
| 157 | - $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; |
|
| 158 | - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user"; |
|
| 159 | - $sql.= $db->order($sortfield,$sortorder); |
|
| 157 | + $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; |
|
| 158 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; |
|
| 159 | + $sql .= $db->order($sortfield, $sortorder); |
|
| 160 | 160 | // TODO: calculate total to display then restore pagination |
| 161 | 161 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
| 162 | 162 | dol_syslog('margin:tabs:productMargins.php', LOG_DEBUG); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if ($result) { |
| 165 | 165 | $num = $db->num_rows($result); |
| 166 | 166 | |
| 167 | - print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&id=$object->id",$sortfield,$sortorder,'',0,0,''); |
|
| 167 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&id=$object->id", $sortfield, $sortorder, '', 0, 0, ''); |
|
| 168 | 168 | |
| 169 | 169 | $i = 0; |
| 170 | 170 | |
@@ -172,52 +172,52 @@ discard block |
||
| 172 | 172 | print '<table class="noborder" width="100%">'; |
| 173 | 173 | |
| 174 | 174 | print '<tr class="liste_titre">'; |
| 175 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&id=".$object->id,'',$sortfield,$sortorder); |
|
| 176 | - print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","&id=".$object->id,'',$sortfield,$sortorder); |
|
| 177 | - print_liste_field_titre("CustomerCode",$_SERVER["PHP_SELF"],"s.code_client","","&id=".$object->id,'',$sortfield,$sortorder); |
|
| 178 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&id=".$object->id,'align="center"',$sortfield,$sortorder); |
|
| 179 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 180 | - print_liste_field_titre("BuyingPrice",$_SERVER["PHP_SELF"],"buying_price","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 181 | - print_liste_field_titre("Qty",$_SERVER["PHP_SELF"],"d.qty","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 182 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 183 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 184 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 185 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 186 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 187 | - print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$object->id,'align="right"',$sortfield,$sortorder); |
|
| 175 | + print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&id=".$object->id, '', $sortfield, $sortorder); |
|
| 176 | + print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&id=".$object->id, '', $sortfield, $sortorder); |
|
| 177 | + print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "&id=".$object->id, '', $sortfield, $sortorder); |
|
| 178 | + print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&id=".$object->id, 'align="center"', $sortfield, $sortorder); |
|
| 179 | + print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 180 | + print_liste_field_titre("BuyingPrice", $_SERVER["PHP_SELF"], "buying_price", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 181 | + print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 182 | + print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 183 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 184 | + print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 185 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 186 | + print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 187 | + print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&id=".$object->id, 'align="right"', $sortfield, $sortorder); |
|
| 188 | 188 | print "</tr>\n"; |
| 189 | 189 | |
| 190 | 190 | $cumul_achat = 0; |
| 191 | 191 | $cumul_vente = 0; |
| 192 | 192 | $cumul_qty = 0; |
| 193 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 193 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 194 | 194 | |
| 195 | 195 | if ($num > 0) { |
| 196 | 196 | while ($i < $num /*&& $i < $conf->liste_limit*/) { |
| 197 | 197 | $objp = $db->fetch_object($result); |
| 198 | 198 | |
| 199 | - $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; |
|
| 200 | - $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; |
|
| 199 | + $marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : ''; |
|
| 200 | + $markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : ''; |
|
| 201 | 201 | |
| 202 | 202 | print '<tr class="oddeven">'; |
| 203 | 203 | print '<td>'; |
| 204 | - $invoicestatic->id=$objp->facid; |
|
| 205 | - $invoicestatic->ref=$objp->ref; |
|
| 204 | + $invoicestatic->id = $objp->facid; |
|
| 205 | + $invoicestatic->ref = $objp->ref; |
|
| 206 | 206 | print $invoicestatic->getNomUrl(1); |
| 207 | 207 | print "</td>\n"; |
| 208 | - print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'</a></td>'; |
|
| 208 | + print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($objp->name, 44).'</a></td>'; |
|
| 209 | 209 | print "<td>".$objp->code_client."</td>\n"; |
| 210 | 210 | print "<td align=\"center\">"; |
| 211 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 211 | + print dol_print_date($db->jdate($objp->datef), 'day')."</td>"; |
|
| 212 | 212 | print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
| 213 | 213 | print "<td align=\"right\">".price($objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
| 214 | 214 | print "<td align=\"right\">".price($objp->qty, null, null, null, null, $rounding)."</td>\n"; |
| 215 | 215 | print "<td align=\"right\">".price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
| 216 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 217 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 218 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 219 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 220 | - print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
|
| 216 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 217 | + print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 218 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 219 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 220 | + print '<td align="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'</td>'; |
|
| 221 | 221 | print "</tr>\n"; |
| 222 | 222 | $i++; |
| 223 | 223 | $cumul_achat += $objp->buying_price; |
@@ -231,13 +231,13 @@ discard block |
||
| 231 | 231 | $totalMargin = $cumul_vente - $cumul_achat; |
| 232 | 232 | if ($totalMargin < 0) |
| 233 | 233 | { |
| 234 | - $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
|
| 235 | - $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
|
| 234 | + $marginRate = ($cumul_achat != 0) ?-1 * (100 * $totalMargin / $cumul_achat) : ''; |
|
| 235 | + $markRate = ($cumul_vente != 0) ?-1 * (100 * $totalMargin / $cumul_vente) : ''; |
|
| 236 | 236 | } |
| 237 | 237 | else |
| 238 | 238 | { |
| 239 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 240 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 239 | + $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : ''; |
|
| 240 | + $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : ''; |
|
| 241 | 241 | } |
| 242 | 242 | print '<tr class="liste_total">'; |
| 243 | 243 | print '<td colspan=4>'.$langs->trans('TotalMargin')."</td>"; |
@@ -245,10 +245,10 @@ discard block |
||
| 245 | 245 | print '<td align="right">'.price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
| 246 | 246 | print '<td align="right">'.price($cumul_qty, null, null, null, null, $rounding)."</td>\n"; |
| 247 | 247 | print '<td align="right">'.price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
| 248 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 249 | - print '<td align="right">'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 250 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 251 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 248 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 249 | + print '<td align="right">'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 250 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 251 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 252 | 252 | print '<td align="right"> </td>'; |
| 253 | 253 | print "</tr>\n"; |
| 254 | 254 | print "</table>"; |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | <script type="text/javascript"> |
| 268 | 268 | $(document).ready(function() { |
| 269 | 269 | $("#totalMargin").html("'. price($totalMargin, null, null, null, null, $rounding).'"); |
| 270 | - $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'"); |
|
| 271 | - $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'"); |
|
| 270 | + $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'"); |
|
| 271 | + $("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'"); |
|
| 272 | 272 | }); |
| 273 | 273 | </script> |
| 274 | 274 | '; |
@@ -122,16 +122,16 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // Margin Rate |
| 124 | 124 | if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
| 125 | - print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">'; |
|
| 126 | - print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 127 | - print '</td></tr>'; |
|
| 125 | + print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">'; |
|
| 126 | + print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 127 | + print '</td></tr>'; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Mark Rate |
| 131 | 131 | if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
| 132 | - print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">'; |
|
| 133 | - print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 134 | - print '</td></tr>'; |
|
| 132 | + print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">'; |
|
| 133 | + print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 134 | + print '</td></tr>'; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | print "</table>"; |
@@ -168,99 +168,99 @@ discard block |
||
| 168 | 168 | $result = $db->query($sql); |
| 169 | 169 | if ($result) |
| 170 | 170 | { |
| 171 | - $num = $db->num_rows($result); |
|
| 172 | - |
|
| 173 | - print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&socid=".$object->id,$sortfield,$sortorder,'',0,0,''); |
|
| 174 | - |
|
| 175 | - $i = 0; |
|
| 176 | - print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table |
|
| 177 | - print "<table class=\"noborder\" width=\"100%\">"; |
|
| 178 | - |
|
| 179 | - print '<tr class="liste_titre">'; |
|
| 180 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$_REQUEST["socid"],'',$sortfield,$sortorder); |
|
| 181 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder); |
|
| 182 | - print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 183 | - print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 184 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 185 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 186 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 187 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 188 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 189 | - print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 190 | - print "</tr>\n"; |
|
| 191 | - |
|
| 192 | - $cumul_achat = 0; |
|
| 193 | - $cumul_vente = 0; |
|
| 194 | - |
|
| 195 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 196 | - |
|
| 197 | - if ($num > 0) |
|
| 198 | - { |
|
| 199 | - while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 200 | - { |
|
| 201 | - $objp = $db->fetch_object($result); |
|
| 202 | - |
|
| 203 | - $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; |
|
| 204 | - $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; |
|
| 205 | - |
|
| 206 | - $sign = ''; |
|
| 207 | - if ($objp->type == Facture::TYPE_CREDIT_NOTE){ |
|
| 208 | - $sign = '-'; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - print '<tr class="oddeven">'; |
|
| 212 | - print '<td>'; |
|
| 213 | - $invoicestatic->id=$objp->facid; |
|
| 214 | - $invoicestatic->ref=$objp->ref; |
|
| 215 | - print $invoicestatic->getNomUrl(1); |
|
| 216 | - print "</td>\n"; |
|
| 217 | - print "<td align=\"center\">"; |
|
| 218 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 219 | - print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 220 | - print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 221 | - print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 222 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 223 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 224 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 225 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 226 | - print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
|
| 227 | - print "</tr>\n"; |
|
| 228 | - $i++; |
|
| 229 | - $cumul_vente += $objp->selling_price; |
|
| 230 | - $cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // affichage totaux marges |
|
| 235 | - |
|
| 236 | - $totalMargin = $cumul_vente - $cumul_achat; |
|
| 237 | - if ($totalMargin < 0) |
|
| 238 | - { |
|
| 239 | - $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
|
| 240 | - $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
|
| 241 | - } |
|
| 242 | - else |
|
| 243 | - { |
|
| 244 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 245 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // Total |
|
| 249 | - print '<tr class="liste_total">'; |
|
| 250 | - print '<td colspan=2>'.$langs->trans('TotalMargin')."</td>"; |
|
| 251 | - print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
| 252 | - print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
| 253 | - print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
| 254 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 255 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 256 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 257 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 258 | - print '<td align="right"> </td>'; |
|
| 259 | - print "</tr>\n"; |
|
| 171 | + $num = $db->num_rows($result); |
|
| 172 | + |
|
| 173 | + print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&socid=".$object->id,$sortfield,$sortorder,'',0,0,''); |
|
| 174 | + |
|
| 175 | + $i = 0; |
|
| 176 | + print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table |
|
| 177 | + print "<table class=\"noborder\" width=\"100%\">"; |
|
| 178 | + |
|
| 179 | + print '<tr class="liste_titre">'; |
|
| 180 | + print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$_REQUEST["socid"],'',$sortfield,$sortorder); |
|
| 181 | + print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder); |
|
| 182 | + print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 183 | + print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 184 | + print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 185 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 186 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 187 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 188 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 189 | + print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 190 | + print "</tr>\n"; |
|
| 191 | + |
|
| 192 | + $cumul_achat = 0; |
|
| 193 | + $cumul_vente = 0; |
|
| 194 | + |
|
| 195 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 196 | + |
|
| 197 | + if ($num > 0) |
|
| 198 | + { |
|
| 199 | + while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 200 | + { |
|
| 201 | + $objp = $db->fetch_object($result); |
|
| 202 | + |
|
| 203 | + $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; |
|
| 204 | + $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; |
|
| 205 | + |
|
| 206 | + $sign = ''; |
|
| 207 | + if ($objp->type == Facture::TYPE_CREDIT_NOTE){ |
|
| 208 | + $sign = '-'; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + print '<tr class="oddeven">'; |
|
| 212 | + print '<td>'; |
|
| 213 | + $invoicestatic->id=$objp->facid; |
|
| 214 | + $invoicestatic->ref=$objp->ref; |
|
| 215 | + print $invoicestatic->getNomUrl(1); |
|
| 216 | + print "</td>\n"; |
|
| 217 | + print "<td align=\"center\">"; |
|
| 218 | + print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 219 | + print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 220 | + print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
|
| 221 | + print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 222 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 223 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 224 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 225 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 226 | + print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
|
| 227 | + print "</tr>\n"; |
|
| 228 | + $i++; |
|
| 229 | + $cumul_vente += $objp->selling_price; |
|
| 230 | + $cumul_achat += ($objp->type == 2 ? -1 : 1) * $objp->buying_price; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // affichage totaux marges |
|
| 235 | + |
|
| 236 | + $totalMargin = $cumul_vente - $cumul_achat; |
|
| 237 | + if ($totalMargin < 0) |
|
| 238 | + { |
|
| 239 | + $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
|
| 240 | + $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
|
| 241 | + } |
|
| 242 | + else |
|
| 243 | + { |
|
| 244 | + $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 245 | + $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // Total |
|
| 249 | + print '<tr class="liste_total">'; |
|
| 250 | + print '<td colspan=2>'.$langs->trans('TotalMargin')."</td>"; |
|
| 251 | + print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
| 252 | + print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
| 253 | + print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
| 254 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 255 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 256 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 257 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 258 | + print '<td align="right"> </td>'; |
|
| 259 | + print "</tr>\n"; |
|
| 260 | 260 | } |
| 261 | 261 | else |
| 262 | 262 | { |
| 263 | - dol_print_error($db); |
|
| 263 | + dol_print_error($db); |
|
| 264 | 264 | } |
| 265 | 265 | print "</table>"; |
| 266 | 266 | print '</div>'; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | else |
| 272 | 272 | { |
| 273 | - dol_print_error('', 'Parameter socid not defined'); |
|
| 273 | + dol_print_error('', 'Parameter socid not defined'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | // Security check |
| 32 | 32 | $socid = GETPOST('socid','int'); |
| 33 | -if (! empty($user->societe_id)) $socid=$user->societe_id; |
|
| 33 | +if (! empty($user->societe_id)) { |
|
| 34 | + $socid=$user->societe_id; |
|
| 35 | +} |
|
| 34 | 36 | $result = restrictedArea($user, 'societe','',''); |
| 35 | 37 | |
| 36 | 38 | |
@@ -43,11 +45,17 @@ discard block |
||
| 43 | 45 | $offset = $conf->liste_limit * $page; |
| 44 | 46 | $pageprev = $page - 1; |
| 45 | 47 | $pagenext = $page + 1; |
| 46 | -if (! $sortorder) $sortorder="DESC"; |
|
| 47 | -if (! $sortfield) $sortfield="f.datef"; |
|
| 48 | +if (! $sortorder) { |
|
| 49 | + $sortorder="DESC"; |
|
| 50 | +} |
|
| 51 | +if (! $sortfield) { |
|
| 52 | + $sortfield="f.datef"; |
|
| 53 | +} |
|
| 48 | 54 | |
| 49 | 55 | $object = new Societe($db); |
| 50 | -if ($socid > 0) $object->fetch($socid); |
|
| 56 | +if ($socid > 0) { |
|
| 57 | + $object->fetch($socid); |
|
| 58 | +} |
|
| 51 | 59 | |
| 52 | 60 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
| 53 | 61 | $hookmanager->initHooks(array('thirdpartymargins','globalcard')); |
@@ -59,7 +67,9 @@ discard block |
||
| 59 | 67 | |
| 60 | 68 | $parameters=array('id'=>$socid); |
| 61 | 69 | $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
| 62 | -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
| 70 | +if ($reshook < 0) { |
|
| 71 | + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
| 72 | +} |
|
| 63 | 73 | |
| 64 | 74 | |
| 65 | 75 | |
@@ -71,7 +81,9 @@ discard block |
||
| 71 | 81 | $form = new Form($db); |
| 72 | 82 | |
| 73 | 83 | $title=$langs->trans("ThirdParty").' - '.$langs->trans("Margins"); |
| 74 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files"); |
|
| 84 | +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) { |
|
| 85 | + $title=$object->name.' - '.$langs->trans("Files"); |
|
| 86 | +} |
|
| 75 | 87 | $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
| 76 | 88 | llxHeader('',$title,$help_url); |
| 77 | 89 | |
@@ -102,7 +114,9 @@ discard block |
||
| 102 | 114 | print '<tr><td class="titlefield">'; |
| 103 | 115 | print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
| 104 | 116 | print $object->code_client; |
| 105 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
| 117 | + if ($object->check_codeclient() <> 0) { |
|
| 118 | + print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
| 119 | + } |
|
| 106 | 120 | print '</td></tr>'; |
| 107 | 121 | } |
| 108 | 122 | |
@@ -111,7 +125,9 @@ discard block |
||
| 111 | 125 | print '<tr><td class="titlefield">'; |
| 112 | 126 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
| 113 | 127 | print $object->code_fournisseur; |
| 114 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
| 128 | + if ($object->check_codefournisseur() <> 0) { |
|
| 129 | + print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
| 130 | + } |
|
| 115 | 131 | print '</td></tr>'; |
| 116 | 132 | } |
| 117 | 133 | |
@@ -158,7 +174,9 @@ discard block |
||
| 158 | 174 | $sql.= " AND d.fk_facture = f.rowid"; |
| 159 | 175 | $sql.= " AND f.fk_soc = $socid"; |
| 160 | 176 | $sql.= " AND d.buy_price_ht IS NOT NULL"; |
| 161 | - if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
|
| 177 | + if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) { |
|
| 178 | + $sql .= " AND d.buy_price_ht <> 0"; |
|
| 179 | + } |
|
| 162 | 180 | $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; |
| 163 | 181 | $sql.= $db->order($sortfield,$sortorder); |
| 164 | 182 | // TODO: calculate total to display then restore pagination |
@@ -182,10 +200,12 @@ discard block |
||
| 182 | 200 | print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
| 183 | 201 | print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
| 184 | 202 | print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
| 185 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 186 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 187 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 188 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 203 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 204 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 205 | + } |
|
| 206 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 207 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 208 | + } |
|
| 189 | 209 | print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
| 190 | 210 | print "</tr>\n"; |
| 191 | 211 | |
@@ -219,10 +239,12 @@ discard block |
||
| 219 | 239 | print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
| 220 | 240 | print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
| 221 | 241 | print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
| 222 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 223 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 224 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 225 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 242 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 243 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 244 | + } |
|
| 245 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 246 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 247 | + } |
|
| 226 | 248 | print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
| 227 | 249 | print "</tr>\n"; |
| 228 | 250 | $i++; |
@@ -238,8 +260,7 @@ discard block |
||
| 238 | 260 | { |
| 239 | 261 | $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
| 240 | 262 | $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
| 241 | - } |
|
| 242 | - else |
|
| 263 | + } else |
|
| 243 | 264 | { |
| 244 | 265 | $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
| 245 | 266 | $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
@@ -251,14 +272,15 @@ discard block |
||
| 251 | 272 | print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
| 252 | 273 | print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
| 253 | 274 | print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
| 254 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 255 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 256 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 257 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 275 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 276 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 277 | + } |
|
| 278 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 279 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 280 | + } |
|
| 258 | 281 | print '<td align="right"> </td>'; |
| 259 | 282 | print "</tr>\n"; |
| 260 | - } |
|
| 261 | - else |
|
| 283 | + } else |
|
| 262 | 284 | { |
| 263 | 285 | dol_print_error($db); |
| 264 | 286 | } |
@@ -267,8 +289,7 @@ discard block |
||
| 267 | 289 | |
| 268 | 290 | print '<br>'; |
| 269 | 291 | $db->free($result); |
| 270 | -} |
|
| 271 | -else |
|
| 292 | +} else |
|
| 272 | 293 | { |
| 273 | 294 | dol_print_error('', 'Parameter socid not defined'); |
| 274 | 295 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
| 27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
| 28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
| 28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
| 29 | 29 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
| 30 | 30 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
| 31 | 31 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | $langs->loadLangs(array("companies", "bills", "products", "margins")); |
| 34 | 34 | |
| 35 | 35 | // Security check |
| 36 | -$socid = GETPOST('socid','int'); |
|
| 37 | -if (! empty($user->societe_id)) $socid=$user->societe_id; |
|
| 38 | -$result = restrictedArea($user, 'societe','',''); |
|
| 36 | +$socid = GETPOST('socid', 'int'); |
|
| 37 | +if (!empty($user->societe_id)) $socid = $user->societe_id; |
|
| 38 | +$result = restrictedArea($user, 'societe', '', ''); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | $mesg = ''; |
| 42 | 42 | |
| 43 | -$sortfield = GETPOST("sortfield",'alpha'); |
|
| 44 | -$sortorder = GETPOST("sortorder",'alpha'); |
|
| 45 | -$page = GETPOST("page",'int'); |
|
| 43 | +$sortfield = GETPOST("sortfield", 'alpha'); |
|
| 44 | +$sortorder = GETPOST("sortorder", 'alpha'); |
|
| 45 | +$page = GETPOST("page", 'int'); |
|
| 46 | 46 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
| 47 | 47 | $offset = $conf->liste_limit * $page; |
| 48 | 48 | $pageprev = $page - 1; |
| 49 | 49 | $pagenext = $page + 1; |
| 50 | -if (! $sortorder) $sortorder="DESC"; |
|
| 51 | -if (! $sortfield) $sortfield="f.datef"; |
|
| 50 | +if (!$sortorder) $sortorder = "DESC"; |
|
| 51 | +if (!$sortfield) $sortfield = "f.datef"; |
|
| 52 | 52 | |
| 53 | 53 | $object = new Societe($db); |
| 54 | 54 | if ($socid > 0) $object->fetch($socid); |
| 55 | 55 | |
| 56 | 56 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
| 57 | -$hookmanager->initHooks(array('thirdpartymargins','globalcard')); |
|
| 57 | +$hookmanager->initHooks(array('thirdpartymargins', 'globalcard')); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | /* |
| 61 | 61 | * Actions |
| 62 | 62 | */ |
| 63 | 63 | |
| 64 | -$parameters=array('id'=>$socid); |
|
| 65 | -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
| 64 | +$parameters = array('id'=>$socid); |
|
| 65 | +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
| 66 | 66 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
| 67 | 67 | |
| 68 | 68 | |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | * View |
| 72 | 72 | */ |
| 73 | 73 | |
| 74 | -$invoicestatic=new Facture($db); |
|
| 74 | +$invoicestatic = new Facture($db); |
|
| 75 | 75 | $form = new Form($db); |
| 76 | 76 | |
| 77 | -$title=$langs->trans("ThirdParty").' - '.$langs->trans("Margins"); |
|
| 78 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files"); |
|
| 79 | -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
| 80 | -llxHeader('',$title,$help_url); |
|
| 77 | +$title = $langs->trans("ThirdParty").' - '.$langs->trans("Margins"); |
|
| 78 | +if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Files"); |
|
| 79 | +$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
| 80 | +llxHeader('', $title, $help_url); |
|
| 81 | 81 | |
| 82 | 82 | if ($socid > 0) |
| 83 | 83 | { |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | dol_fiche_head($head, 'margin', $langs->trans("ThirdParty"), -1, 'company'); |
| 94 | 94 | |
| 95 | 95 | // $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
| 96 | - $linkback = '<a href="' . BASE_URI . '?controller=societe&method=list&restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; |
|
| 96 | + $linkback = '<a href="'.BASE_URI.'?controller=societe&method=list&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
|
| 97 | 97 | |
| 98 | - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
|
| 98 | + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom'); |
|
| 99 | 99 | |
| 100 | 100 | print '<div class="fichecenter">'; |
| 101 | 101 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | print '</td></tr>'; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire)) |
|
| 114 | + if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire)) |
|
| 115 | 115 | { |
| 116 | 116 | print '<tr><td class="titlefield">'; |
| 117 | 117 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | print '</td></tr>'; |
| 127 | 127 | |
| 128 | 128 | // Margin Rate |
| 129 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 129 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 130 | 130 | print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="3">'; |
| 131 | 131 | print '<span id="marginRate"></span>'; // set by jquery (see below) |
| 132 | 132 | print '</td></tr>'; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Mark Rate |
| 136 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 136 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 137 | 137 | print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="3">'; |
| 138 | 138 | print '<span id="markRate"></span>'; // set by jquery (see below) |
| 139 | 139 | print '</td></tr>'; |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | print '<br>'; |
| 150 | 150 | |
| 151 | 151 | $sql = "SELECT distinct s.nom, s.rowid as socid, s.code_client,"; |
| 152 | - $sql.= " f.rowid as facid, f.ref, f.total as total_ht,"; |
|
| 153 | - $sql.= " f.datef, f.paye, f.fk_statut as statut, f.type,"; |
|
| 154 | - $sql.= " sum(d.total_ht) as selling_price,"; // may be negative or positive |
|
| 155 | - $sql.= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive |
|
| 156 | - $sql.= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // always positive |
|
| 157 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 158 | - $sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 159 | - $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 160 | - $sql.= " WHERE f.fk_soc = s.rowid"; |
|
| 161 | - $sql.= " AND f.fk_statut > 0"; |
|
| 162 | - $sql.= " AND f.entity = ".$conf->entity; |
|
| 163 | - $sql.= " AND d.fk_facture = f.rowid"; |
|
| 164 | - $sql.= " AND f.fk_soc = $socid"; |
|
| 165 | - $sql.= " AND d.buy_price_ht IS NOT NULL"; |
|
| 152 | + $sql .= " f.rowid as facid, f.ref, f.total as total_ht,"; |
|
| 153 | + $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,"; |
|
| 154 | + $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive |
|
| 155 | + $sql .= " sum(d.qty * d.buy_price_ht) as buying_price,"; // always positive |
|
| 156 | + $sql .= " sum(abs(d.total_ht) - (d.buy_price_ht * d.qty)) as marge"; // always positive |
|
| 157 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 158 | + $sql .= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 159 | + $sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 160 | + $sql .= " WHERE f.fk_soc = s.rowid"; |
|
| 161 | + $sql .= " AND f.fk_statut > 0"; |
|
| 162 | + $sql .= " AND f.entity = ".$conf->entity; |
|
| 163 | + $sql .= " AND d.fk_facture = f.rowid"; |
|
| 164 | + $sql .= " AND f.fk_soc = $socid"; |
|
| 165 | + $sql .= " AND d.buy_price_ht IS NOT NULL"; |
|
| 166 | 166 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
| 167 | - $sql.= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; |
|
| 168 | - $sql.= $db->order($sortfield,$sortorder); |
|
| 167 | + $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut, f.type"; |
|
| 168 | + $sql .= $db->order($sortfield, $sortorder); |
|
| 169 | 169 | // TODO: calculate total to display then restore pagination |
| 170 | 170 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
| 171 | 171 | |
@@ -175,29 +175,29 @@ discard block |
||
| 175 | 175 | { |
| 176 | 176 | $num = $db->num_rows($result); |
| 177 | 177 | |
| 178 | - print_barre_liste($langs->trans("MarginDetails"),$page,$_SERVER["PHP_SELF"],"&socid=".$object->id,$sortfield,$sortorder,'',0,0,''); |
|
| 178 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&socid=".$object->id, $sortfield, $sortorder, '', 0, 0, ''); |
|
| 179 | 179 | |
| 180 | 180 | $i = 0; |
| 181 | - print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table |
|
| 181 | + print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table |
|
| 182 | 182 | print "<table class=\"noborder\" width=\"100%\">"; |
| 183 | 183 | |
| 184 | 184 | print '<tr class="liste_titre">'; |
| 185 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$_REQUEST["socid"],'',$sortfield,$sortorder); |
|
| 186 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$_REQUEST["socid"],'align="center"',$sortfield,$sortorder); |
|
| 187 | - print_liste_field_titre("SoldAmount",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 188 | - print_liste_field_titre("PurchasedAmount",$_SERVER["PHP_SELF"],"buying_price","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 189 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 190 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 191 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 192 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 193 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 194 | - print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&socid=".$_REQUEST["socid"],'align="right"',$sortfield,$sortorder); |
|
| 185 | + print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&socid=".$_REQUEST["socid"], '', $sortfield, $sortorder); |
|
| 186 | + print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&socid=".$_REQUEST["socid"], 'align="center"', $sortfield, $sortorder); |
|
| 187 | + print_liste_field_titre("SoldAmount", $_SERVER["PHP_SELF"], "selling_price", "", "&socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder); |
|
| 188 | + print_liste_field_titre("PurchasedAmount", $_SERVER["PHP_SELF"], "buying_price", "", "&socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder); |
|
| 189 | + print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder); |
|
| 190 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 191 | + print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder); |
|
| 192 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 193 | + print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder); |
|
| 194 | + print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", "&socid=".$_REQUEST["socid"], 'align="right"', $sortfield, $sortorder); |
|
| 195 | 195 | print "</tr>\n"; |
| 196 | 196 | |
| 197 | 197 | $cumul_achat = 0; |
| 198 | 198 | $cumul_vente = 0; |
| 199 | 199 | |
| 200 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 200 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 201 | 201 | |
| 202 | 202 | if ($num > 0) |
| 203 | 203 | { |
@@ -205,30 +205,30 @@ discard block |
||
| 205 | 205 | { |
| 206 | 206 | $objp = $db->fetch_object($result); |
| 207 | 207 | |
| 208 | - $marginRate = ($objp->buying_price != 0)?(100 * $objp->marge / $objp->buying_price):'' ; |
|
| 209 | - $markRate = ($objp->selling_price != 0)?(100 * $objp->marge / $objp->selling_price):'' ; |
|
| 208 | + $marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : ''; |
|
| 209 | + $markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : ''; |
|
| 210 | 210 | |
| 211 | 211 | $sign = ''; |
| 212 | - if ($objp->type == Facture::TYPE_CREDIT_NOTE){ |
|
| 212 | + if ($objp->type == Facture::TYPE_CREDIT_NOTE) { |
|
| 213 | 213 | $sign = '-'; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | print '<tr class="oddeven">'; |
| 217 | 217 | print '<td>'; |
| 218 | - $invoicestatic->id=$objp->facid; |
|
| 219 | - $invoicestatic->ref=$objp->ref; |
|
| 218 | + $invoicestatic->id = $objp->facid; |
|
| 219 | + $invoicestatic->ref = $objp->ref; |
|
| 220 | 220 | print $invoicestatic->getNomUrl(1); |
| 221 | 221 | print "</td>\n"; |
| 222 | 222 | print "<td align=\"center\">"; |
| 223 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 223 | + print dol_print_date($db->jdate($objp->datef), 'day')."</td>"; |
|
| 224 | 224 | print "<td align=\"right\">".price($objp->selling_price, null, null, null, null, $rounding)."</td>\n"; |
| 225 | 225 | print "<td align=\"right\">".price(($objp->type == 2 ? -1 : 1) * $objp->buying_price, null, null, null, null, $rounding)."</td>\n"; |
| 226 | 226 | print "<td align=\"right\">".$sign.price($objp->marge, null, null, null, null, $rounding)."</td>\n"; |
| 227 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 228 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':$sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 229 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 230 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 231 | - print '<td align="right">'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'</td>'; |
|
| 227 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 228 | + print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : $sign.price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 229 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 230 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 231 | + print '<td align="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'</td>'; |
|
| 232 | 232 | print "</tr>\n"; |
| 233 | 233 | $i++; |
| 234 | 234 | $cumul_vente += $objp->selling_price; |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | $totalMargin = $cumul_vente - $cumul_achat; |
| 242 | 242 | if ($totalMargin < 0) |
| 243 | 243 | { |
| 244 | - $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
|
| 245 | - $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
|
| 244 | + $marginRate = ($cumul_achat != 0) ?-1 * (100 * $totalMargin / $cumul_achat) : ''; |
|
| 245 | + $markRate = ($cumul_vente != 0) ?-1 * (100 * $totalMargin / $cumul_vente) : ''; |
|
| 246 | 246 | } |
| 247 | 247 | else |
| 248 | 248 | { |
| 249 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 250 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 249 | + $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : ''; |
|
| 250 | + $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : ''; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // Total |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
| 257 | 257 | print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
| 258 | 258 | print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
| 259 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 260 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 261 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 262 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 259 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 260 | + print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 261 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 262 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 263 | 263 | print '<td align="right"> </td>'; |
| 264 | 264 | print "</tr>\n"; |
| 265 | 265 | } |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | <script type="text/javascript"> |
| 284 | 284 | $(document).ready(function() { |
| 285 | 285 | $("#totalMargin").html("'. price($totalMargin, null, null, null, null, $rounding).'"); |
| 286 | - $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'"); |
|
| 287 | - $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'"); |
|
| 286 | + $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'"); |
|
| 287 | + $("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'"); |
|
| 288 | 288 | }); |
| 289 | 289 | </script> |
| 290 | 290 | '; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0) |
| 73 | 73 | { |
| 74 | - setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
|
| 74 | + setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
|
| 75 | 75 | } |
| 76 | 76 | else |
| 77 | 77 | { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0) |
| 85 | 85 | { |
| 86 | - setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
|
| 86 | + setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
|
| 87 | 87 | } |
| 88 | 88 | else |
| 89 | 89 | { |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0) |
| 97 | 97 | { |
| 98 | - setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
|
| 98 | + setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
|
| 99 | 99 | } |
| 100 | 100 | else |
| 101 | 101 | { |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | print '<td>'; |
| 138 | 138 | print ' <input type="radio" name="MARGIN_TYPE" value="1" '; |
| 139 | 139 | if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') |
| 140 | - print 'checked '; |
|
| 140 | + print 'checked '; |
|
| 141 | 141 | print '/> '; |
| 142 | 142 | print $langs->trans('MargeType1'); |
| 143 | 143 | print '<br>'; |
@@ -165,18 +165,18 @@ discard block |
||
| 165 | 165 | print '<td colspan="2" align="center">'; |
| 166 | 166 | if (! empty($conf->use_javascript_ajax)) |
| 167 | 167 | { |
| 168 | - print ajax_constantonoff('DISPLAY_MARGIN_RATES'); |
|
| 168 | + print ajax_constantonoff('DISPLAY_MARGIN_RATES'); |
|
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | 171 | { |
| 172 | - if (empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 173 | - { |
|
| 174 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 175 | - } |
|
| 176 | - else |
|
| 177 | - { |
|
| 178 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 179 | - } |
|
| 172 | + if (empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 173 | + { |
|
| 174 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 175 | + } |
|
| 176 | + else |
|
| 177 | + { |
|
| 178 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 179 | + } |
|
| 180 | 180 | } |
| 181 | 181 | print '</td>'; |
| 182 | 182 | print '<td>'.$langs->trans('MarginRate').' = '.$langs->trans('Margin').' / '.$langs->trans('BuyingPrice').'</td>'; |
@@ -188,18 +188,18 @@ discard block |
||
| 188 | 188 | print '<td colspan="2" align="center">'; |
| 189 | 189 | if (! empty($conf->use_javascript_ajax)) |
| 190 | 190 | { |
| 191 | - print ajax_constantonoff('DISPLAY_MARK_RATES'); |
|
| 191 | + print ajax_constantonoff('DISPLAY_MARK_RATES'); |
|
| 192 | 192 | } |
| 193 | 193 | else |
| 194 | 194 | { |
| 195 | - if (empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 196 | - { |
|
| 197 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 198 | - } |
|
| 199 | - else |
|
| 200 | - { |
|
| 201 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 202 | - } |
|
| 195 | + if (empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 196 | + { |
|
| 197 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 198 | + } |
|
| 199 | + else |
|
| 200 | + { |
|
| 201 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 202 | + } |
|
| 203 | 203 | } |
| 204 | 204 | print '</td>'; |
| 205 | 205 | print '<td>'.$langs->trans('MarkRate').' = '.$langs->trans('Margin').' / '.$langs->trans('SellingPrice').'</td>'; |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | print '<td colspan="2" align="center">'; |
| 212 | 212 | if (! empty($conf->use_javascript_ajax)) |
| 213 | 213 | { |
| 214 | - print ajax_constantonoff('ForceBuyingPriceIfNull'); |
|
| 214 | + print ajax_constantonoff('ForceBuyingPriceIfNull'); |
|
| 215 | 215 | } |
| 216 | 216 | else |
| 217 | 217 | { |
| 218 | - if (empty($conf->global->ForceBuyingPriceIfNull)) |
|
| 219 | - { |
|
| 220 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 221 | - } |
|
| 222 | - else |
|
| 223 | - { |
|
| 224 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 225 | - } |
|
| 218 | + if (empty($conf->global->ForceBuyingPriceIfNull)) |
|
| 219 | + { |
|
| 220 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 221 | + } |
|
| 222 | + else |
|
| 223 | + { |
|
| 224 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | print '</td>'; |
| 228 | 228 | print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>'; |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | // GLOBAL DISCOUNT MANAGEMENT |
| 232 | 232 | $methods = array( |
| 233 | - 1 => $langs->trans('UseDiscountAsProduct'), |
|
| 234 | - 2 => $langs->trans('UseDiscountAsService'), |
|
| 235 | - 3 => $langs->trans('UseDiscountOnTotal') |
|
| 233 | + 1 => $langs->trans('UseDiscountAsProduct'), |
|
| 234 | + 2 => $langs->trans('UseDiscountAsService'), |
|
| 235 | + 3 => $langs->trans('UseDiscountOnTotal') |
|
| 236 | 236 | ); |
| 237 | 237 | |
| 238 | 238 | |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $langs->loadLangs(array("admin", "bills", "margins", "stocks")); |
| 33 | 33 | |
| 34 | -if (! $user->admin) accessforbidden(); |
|
| 34 | +if (!$user->admin) accessforbidden(); |
|
| 35 | 35 | |
| 36 | -$action=GETPOST('action','alpha'); |
|
| 36 | +$action = GETPOST('action', 'alpha'); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | /* |
| 40 | 40 | * Action |
| 41 | 41 | */ |
| 42 | -if (preg_match('/set_([a-z0-9_\-]+)/i',$action,$reg)) |
|
| 42 | +if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) |
|
| 43 | 43 | { |
| 44 | - $code=$reg[1]; |
|
| 44 | + $code = $reg[1]; |
|
| 45 | 45 | if (dolibarr_set_const($db, $code, 1, 'yesno', 0, '', $conf->entity) > 0) |
| 46 | 46 | { |
| 47 | 47 | header("Location: ".$_SERVER["PHP_SELF"]); |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -if (preg_match('/del_([a-z0-9_\-]+)/i',$action,$reg)) |
|
| 56 | +if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) |
|
| 57 | 57 | { |
| 58 | - $code=$reg[1]; |
|
| 58 | + $code = $reg[1]; |
|
| 59 | 59 | if (dolibarr_del_const($db, $code, $conf->entity) > 0) |
| 60 | 60 | { |
| 61 | 61 | header("Location: ".$_SERVER["PHP_SELF"]); |
@@ -107,18 +107,18 @@ discard block |
||
| 107 | 107 | * View |
| 108 | 108 | */ |
| 109 | 109 | |
| 110 | -llxHeader('',$langs->trans("margesSetup")); |
|
| 110 | +llxHeader('', $langs->trans("margesSetup")); |
|
| 111 | 111 | |
| 112 | 112 | |
| 113 | -$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
|
| 114 | -print load_fiche_titre($langs->trans("margesSetup"),$linkback,'title_setup'); |
|
| 113 | +$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
|
| 114 | +print load_fiche_titre($langs->trans("margesSetup"), $linkback, 'title_setup'); |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | $head = marges_admin_prepare_head(); |
| 118 | 118 | |
| 119 | 119 | dol_fiche_head($head, 'parameters', $langs->trans("Margins"), -1, 'margin'); |
| 120 | 120 | |
| 121 | -print load_fiche_titre($langs->trans("MemberMainOptions"),'',''); |
|
| 121 | +print load_fiche_titre($langs->trans("MemberMainOptions"), '', ''); |
|
| 122 | 122 | print '<table class="noborder" width="100%">'; |
| 123 | 123 | print '<tr class="liste_titre">'; |
| 124 | 124 | print '<td width=300>'.$langs->trans("Description").'</td>'; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | print '<tr class="oddeven">'; |
| 164 | 164 | print '<td>'.$langs->trans("DisplayMarginRates").'</td>'; |
| 165 | 165 | print '<td colspan="2" align="center">'; |
| 166 | -if (! empty($conf->use_javascript_ajax)) |
|
| 166 | +if (!empty($conf->use_javascript_ajax)) |
|
| 167 | 167 | { |
| 168 | 168 | print ajax_constantonoff('DISPLAY_MARGIN_RATES'); |
| 169 | 169 | } |
@@ -171,11 +171,11 @@ discard block |
||
| 171 | 171 | { |
| 172 | 172 | if (empty($conf->global->DISPLAY_MARGIN_RATES)) |
| 173 | 173 | { |
| 174 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 174 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; |
|
| 175 | 175 | } |
| 176 | 176 | else |
| 177 | 177 | { |
| 178 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 178 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"), 'on').'</a>'; |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | print '</td>'; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | print '<tr class="oddeven">'; |
| 187 | 187 | print '<td>'.$langs->trans("DisplayMarkRates").'</td>'; |
| 188 | 188 | print '<td colspan="2" align="center">'; |
| 189 | -if (! empty($conf->use_javascript_ajax)) |
|
| 189 | +if (!empty($conf->use_javascript_ajax)) |
|
| 190 | 190 | { |
| 191 | 191 | print ajax_constantonoff('DISPLAY_MARK_RATES'); |
| 192 | 192 | } |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | { |
| 195 | 195 | if (empty($conf->global->DISPLAY_MARK_RATES)) |
| 196 | 196 | { |
| 197 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 197 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; |
|
| 198 | 198 | } |
| 199 | 199 | else |
| 200 | 200 | { |
| 201 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 201 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"), 'on').'</a>'; |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | print '</td>'; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | print '<tr class="oddeven">'; |
| 210 | 210 | print '<td>'.$langs->trans("ForceBuyingPriceIfNull").'</td>'; |
| 211 | 211 | print '<td colspan="2" align="center">'; |
| 212 | -if (! empty($conf->use_javascript_ajax)) |
|
| 212 | +if (!empty($conf->use_javascript_ajax)) |
|
| 213 | 213 | { |
| 214 | 214 | print ajax_constantonoff('ForceBuyingPriceIfNull'); |
| 215 | 215 | } |
@@ -217,11 +217,11 @@ discard block |
||
| 217 | 217 | { |
| 218 | 218 | if (empty($conf->global->ForceBuyingPriceIfNull)) |
| 219 | 219 | { |
| 220 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
| 220 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; |
|
| 221 | 221 | } |
| 222 | 222 | else |
| 223 | 223 | { |
| 224 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
|
| 224 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"), 'on').'</a>'; |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | print '</td>'; |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | print '<td align="left">'; |
| 261 | 261 | $formcompany = new FormCompany($db); |
| 262 | 262 | $facture = new Facture($db); |
| 263 | -print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE","internal","code",1); |
|
| 263 | +print $formcompany->selectTypeContact($facture, $conf->global->AGENT_CONTACT_TYPE, "AGENT_CONTACT_TYPE", "internal", "code", 1); |
|
| 264 | 264 | print '</td>'; |
| 265 | 265 | print '<td>'; |
| 266 | 266 | print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $langs->loadLangs(array("admin", "bills", "margins", "stocks")); |
| 33 | 33 | |
| 34 | -if (! $user->admin) accessforbidden(); |
|
| 34 | +if (! $user->admin) { |
|
| 35 | + accessforbidden(); |
|
| 36 | +} |
|
| 35 | 37 | |
| 36 | 38 | $action=GETPOST('action','alpha'); |
| 37 | 39 | |
@@ -46,8 +48,7 @@ discard block |
||
| 46 | 48 | { |
| 47 | 49 | header("Location: ".$_SERVER["PHP_SELF"]); |
| 48 | 50 | exit; |
| 49 | - } |
|
| 50 | - else |
|
| 51 | + } else |
|
| 51 | 52 | { |
| 52 | 53 | dol_print_error($db); |
| 53 | 54 | } |
@@ -60,8 +61,7 @@ discard block |
||
| 60 | 61 | { |
| 61 | 62 | header("Location: ".$_SERVER["PHP_SELF"]); |
| 62 | 63 | exit; |
| 63 | - } |
|
| 64 | - else |
|
| 64 | + } else |
|
| 65 | 65 | { |
| 66 | 66 | dol_print_error($db); |
| 67 | 67 | } |
@@ -72,8 +72,7 @@ discard block |
||
| 72 | 72 | if (dolibarr_set_const($db, 'MARGIN_METHODE_FOR_DISCOUNT', $_POST['MARGIN_METHODE_FOR_DISCOUNT'], 'chaine', 0, '', $conf->entity) > 0) |
| 73 | 73 | { |
| 74 | 74 | setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
| 75 | - } |
|
| 76 | - else |
|
| 75 | + } else |
|
| 77 | 76 | { |
| 78 | 77 | dol_print_error($db); |
| 79 | 78 | } |
@@ -84,8 +83,7 @@ discard block |
||
| 84 | 83 | if (dolibarr_set_const($db, 'MARGIN_TYPE', $_POST['MARGIN_TYPE'], 'chaine', 0, '', $conf->entity) > 0) |
| 85 | 84 | { |
| 86 | 85 | setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
| 87 | - } |
|
| 88 | - else |
|
| 86 | + } else |
|
| 89 | 87 | { |
| 90 | 88 | dol_print_error($db); |
| 91 | 89 | } |
@@ -96,8 +94,7 @@ discard block |
||
| 96 | 94 | if (dolibarr_set_const($db, 'AGENT_CONTACT_TYPE', $_POST['AGENT_CONTACT_TYPE'], 'chaine', 0, '', $conf->entity) > 0) |
| 97 | 95 | { |
| 98 | 96 | setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); |
| 99 | - } |
|
| 100 | - else |
|
| 97 | + } else |
|
| 101 | 98 | { |
| 102 | 99 | dol_print_error($db); |
| 103 | 100 | } |
@@ -136,18 +133,23 @@ discard block |
||
| 136 | 133 | print '<td>'.$langs->trans("MARGIN_TYPE").'</td>'; |
| 137 | 134 | print '<td>'; |
| 138 | 135 | print ' <input type="radio" name="MARGIN_TYPE" value="1" '; |
| 139 | -if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') |
|
| 136 | +if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') { |
|
| 140 | 137 | print 'checked '; |
| 138 | +} |
|
| 141 | 139 | print '/> '; |
| 142 | 140 | print $langs->trans('MargeType1'); |
| 143 | 141 | print '<br>'; |
| 144 | 142 | print ' <input type="radio" name="MARGIN_TYPE" value="pmp" '; |
| 145 | -if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') print 'checked '; |
|
| 143 | +if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') { |
|
| 144 | + print 'checked '; |
|
| 145 | +} |
|
| 146 | 146 | print '/> '; |
| 147 | 147 | print $langs->trans('MargeType2'); |
| 148 | 148 | print '<br>'; |
| 149 | 149 | print ' <input type="radio" name="MARGIN_TYPE" value="costprice" '; |
| 150 | -if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') print 'checked '; |
|
| 150 | +if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') { |
|
| 151 | + print 'checked '; |
|
| 152 | +} |
|
| 151 | 153 | print '/> '; |
| 152 | 154 | print $langs->trans('MargeType3'); |
| 153 | 155 | print '</td>'; |
@@ -166,14 +168,12 @@ discard block |
||
| 166 | 168 | if (! empty($conf->use_javascript_ajax)) |
| 167 | 169 | { |
| 168 | 170 | print ajax_constantonoff('DISPLAY_MARGIN_RATES'); |
| 169 | -} |
|
| 170 | -else |
|
| 171 | +} else |
|
| 171 | 172 | { |
| 172 | 173 | if (empty($conf->global->DISPLAY_MARGIN_RATES)) |
| 173 | 174 | { |
| 174 | 175 | print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
| 175 | - } |
|
| 176 | - else |
|
| 176 | + } else |
|
| 177 | 177 | { |
| 178 | 178 | print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARGIN_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
| 179 | 179 | } |
@@ -189,14 +189,12 @@ discard block |
||
| 189 | 189 | if (! empty($conf->use_javascript_ajax)) |
| 190 | 190 | { |
| 191 | 191 | print ajax_constantonoff('DISPLAY_MARK_RATES'); |
| 192 | -} |
|
| 193 | -else |
|
| 192 | +} else |
|
| 194 | 193 | { |
| 195 | 194 | if (empty($conf->global->DISPLAY_MARK_RATES)) |
| 196 | 195 | { |
| 197 | 196 | print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
| 198 | - } |
|
| 199 | - else |
|
| 197 | + } else |
|
| 200 | 198 | { |
| 201 | 199 | print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_DISPLAY_MARK_RATES">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
| 202 | 200 | } |
@@ -212,14 +210,12 @@ discard block |
||
| 212 | 210 | if (! empty($conf->use_javascript_ajax)) |
| 213 | 211 | { |
| 214 | 212 | print ajax_constantonoff('ForceBuyingPriceIfNull'); |
| 215 | -} |
|
| 216 | -else |
|
| 213 | +} else |
|
| 217 | 214 | { |
| 218 | 215 | if (empty($conf->global->ForceBuyingPriceIfNull)) |
| 219 | 216 | { |
| 220 | 217 | print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
| 221 | - } |
|
| 222 | - else |
|
| 218 | + } else |
|
| 223 | 219 | { |
| 224 | 220 | print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_ForceBuyingPriceIfNull">'.img_picto($langs->trans("Enabled"),'on').'</a>'; |
| 225 | 221 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | $startdate=$enddate=''; |
| 59 | 59 | |
| 60 | 60 | if (!empty($_POST['startdatemonth'])) |
| 61 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 61 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 62 | 62 | if (!empty($_POST['enddatemonth'])) |
| 63 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 63 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | /* |
@@ -92,28 +92,28 @@ discard block |
||
| 92 | 92 | $client = false; |
| 93 | 93 | if ($socid > 0) { |
| 94 | 94 | |
| 95 | - $soc = new Societe($db); |
|
| 96 | - $soc->fetch($socid); |
|
| 97 | - |
|
| 98 | - if ($soc->client) |
|
| 99 | - { |
|
| 100 | - print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 101 | - print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 102 | - print $form->select_company($socid, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 103 | - //$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid','client=1 OR client=3',1,0,1); |
|
| 104 | - print '</td></tr>'; |
|
| 105 | - |
|
| 106 | - $client = true; |
|
| 107 | - if (! $sortorder) $sortorder="DESC"; |
|
| 108 | - if (! $sortfield) $sortfield="f.datef"; |
|
| 109 | - } |
|
| 95 | + $soc = new Societe($db); |
|
| 96 | + $soc->fetch($socid); |
|
| 97 | + |
|
| 98 | + if ($soc->client) |
|
| 99 | + { |
|
| 100 | + print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 101 | + print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 102 | + print $form->select_company($socid, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 103 | + //$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid','client=1 OR client=3',1,0,1); |
|
| 104 | + print '</td></tr>'; |
|
| 105 | + |
|
| 106 | + $client = true; |
|
| 107 | + if (! $sortorder) $sortorder="DESC"; |
|
| 108 | + if (! $sortfield) $sortfield="f.datef"; |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | else { |
| 112 | - print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 113 | - print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 114 | - print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 115 | - //$form->form_thirdparty($_SERVER['PHP_SELF'],null,'socid','client=1 OR client=3',1,0,1); |
|
| 116 | - print '</td></tr>'; |
|
| 112 | + print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 113 | + print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 114 | + print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 115 | + //$form->form_thirdparty($_SERVER['PHP_SELF'],null,'socid','client=1 OR client=3',1,0,1); |
|
| 116 | + print '</td></tr>'; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $sortfield = GETPOST("sortfield",'alpha'); |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | if (! $sortorder) $sortorder="ASC"; |
| 122 | 122 | if (! $sortfield) |
| 123 | 123 | { |
| 124 | - if ($client) |
|
| 125 | - { |
|
| 126 | - $sortfield="f.datef"; |
|
| 127 | - $sortorder="DESC"; |
|
| 128 | - } |
|
| 129 | - else |
|
| 130 | - { |
|
| 131 | - $sortfield="s.nom"; |
|
| 132 | - $sortorder="ASC"; |
|
| 133 | - } |
|
| 124 | + if ($client) |
|
| 125 | + { |
|
| 126 | + $sortfield="f.datef"; |
|
| 127 | + $sortorder="DESC"; |
|
| 128 | + } |
|
| 129 | + else |
|
| 130 | + { |
|
| 131 | + $sortfield="s.nom"; |
|
| 132 | + $sortorder="ASC"; |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Products |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $TProducts = array(); |
| 140 | 140 | foreach($TRes as $prod) { |
| 141 | - $TProducts[$prod['key']] = $prod['label']; |
|
| 141 | + $TProducts[$prod['key']] = $prod['label']; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>'; |
@@ -182,16 +182,16 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | // Margin Rate |
| 184 | 184 | if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
| 185 | - print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
|
| 186 | - print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 187 | - print '</td></tr>'; |
|
| 185 | + print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
|
| 186 | + print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 187 | + print '</td></tr>'; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // Mark Rate |
| 191 | 191 | if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
| 192 | - print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
|
| 193 | - print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 194 | - print '</td></tr>'; |
|
| 192 | + print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
|
| 193 | + print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 194 | + print '</td></tr>'; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | print "</table>"; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
| 212 | 212 | $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
| 213 | 213 | if(! empty($TSelectedCats)) { |
| 214 | - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; |
|
| 214 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | $sql.= " AND d.fk_facture = f.rowid"; |
| 224 | 224 | $sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
| 225 | 225 | if(! empty($TSelectedProducts)) { |
| 226 | - $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')'; |
|
| 226 | + $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')'; |
|
| 227 | 227 | } |
| 228 | 228 | if(! empty($TSelectedCats)) { |
| 229 | - $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
| 229 | + $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
| 230 | 230 | } |
| 231 | 231 | if (!empty($startdate)) |
| 232 | 232 | $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
@@ -245,127 +245,127 @@ discard block |
||
| 245 | 245 | $result = $db->query($sql); |
| 246 | 246 | if ($result) |
| 247 | 247 | { |
| 248 | - $num = $db->num_rows($result); |
|
| 249 | - |
|
| 250 | - print '<br>'; |
|
| 251 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
| 252 | - |
|
| 253 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 254 | - $labelcostprice='BuyingPrice'; |
|
| 255 | - else // value is 'costprice' or 'pmp' |
|
| 256 | - $labelcostprice='CostPrice'; |
|
| 257 | - |
|
| 258 | - $i = 0; |
|
| 259 | - print "<table class=\"noborder\" width=\"100%\">"; |
|
| 260 | - |
|
| 261 | - print '<tr class="liste_titre">'; |
|
| 262 | - if (! empty($client)) { |
|
| 263 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 264 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); |
|
| 265 | - } |
|
| 266 | - else |
|
| 267 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 268 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 269 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 270 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 271 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 272 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 273 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 274 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 275 | - print "</tr>\n"; |
|
| 276 | - |
|
| 277 | - $cumul_achat = 0; |
|
| 278 | - $cumul_vente = 0; |
|
| 279 | - |
|
| 280 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 281 | - |
|
| 282 | - if ($num > 0) |
|
| 283 | - { |
|
| 284 | - while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 285 | - { |
|
| 286 | - $objp = $db->fetch_object($result); |
|
| 287 | - |
|
| 288 | - $pa = $objp->buying_price; |
|
| 289 | - $pv = $objp->selling_price; |
|
| 290 | - $marge = $objp->marge; |
|
| 291 | - |
|
| 292 | - if ($marge < 0) |
|
| 293 | - { |
|
| 294 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 295 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 296 | - } |
|
| 297 | - else |
|
| 298 | - { |
|
| 299 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 300 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - print '<tr class="oddeven">'; |
|
| 304 | - if ($client) { |
|
| 305 | - print '<td>'; |
|
| 306 | - $invoicestatic->id=$objp->facid; |
|
| 307 | - $invoicestatic->ref=$objp->ref; |
|
| 308 | - print $invoicestatic->getNomUrl(1); |
|
| 309 | - print "</td>\n"; |
|
| 310 | - print "<td align=\"center\">"; |
|
| 311 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 312 | - } |
|
| 313 | - else { |
|
| 314 | - $companystatic->id=$objp->socid; |
|
| 315 | - $companystatic->name=$objp->name; |
|
| 316 | - $companystatic->client=$objp->client; |
|
| 317 | - print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n"; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
| 321 | - print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
| 322 | - print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 323 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 324 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 325 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 326 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 327 | - print "</tr>\n"; |
|
| 328 | - |
|
| 329 | - $i++; |
|
| 330 | - $cumul_achat += $objp->buying_price; |
|
| 331 | - $cumul_vente += $objp->selling_price; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // affichage totaux marges |
|
| 336 | - |
|
| 337 | - $totalMargin = $cumul_vente - $cumul_achat; |
|
| 338 | - /*if ($totalMargin < 0) |
|
| 248 | + $num = $db->num_rows($result); |
|
| 249 | + |
|
| 250 | + print '<br>'; |
|
| 251 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
| 252 | + |
|
| 253 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 254 | + $labelcostprice='BuyingPrice'; |
|
| 255 | + else // value is 'costprice' or 'pmp' |
|
| 256 | + $labelcostprice='CostPrice'; |
|
| 257 | + |
|
| 258 | + $i = 0; |
|
| 259 | + print "<table class=\"noborder\" width=\"100%\">"; |
|
| 260 | + |
|
| 261 | + print '<tr class="liste_titre">'; |
|
| 262 | + if (! empty($client)) { |
|
| 263 | + print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 264 | + print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); |
|
| 265 | + } |
|
| 266 | + else |
|
| 267 | + print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 268 | + print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 269 | + print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 270 | + print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 271 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 272 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 273 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 274 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 275 | + print "</tr>\n"; |
|
| 276 | + |
|
| 277 | + $cumul_achat = 0; |
|
| 278 | + $cumul_vente = 0; |
|
| 279 | + |
|
| 280 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 281 | + |
|
| 282 | + if ($num > 0) |
|
| 283 | + { |
|
| 284 | + while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 285 | + { |
|
| 286 | + $objp = $db->fetch_object($result); |
|
| 287 | + |
|
| 288 | + $pa = $objp->buying_price; |
|
| 289 | + $pv = $objp->selling_price; |
|
| 290 | + $marge = $objp->marge; |
|
| 291 | + |
|
| 292 | + if ($marge < 0) |
|
| 293 | + { |
|
| 294 | + $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 295 | + $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 296 | + } |
|
| 297 | + else |
|
| 298 | + { |
|
| 299 | + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 300 | + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + print '<tr class="oddeven">'; |
|
| 304 | + if ($client) { |
|
| 305 | + print '<td>'; |
|
| 306 | + $invoicestatic->id=$objp->facid; |
|
| 307 | + $invoicestatic->ref=$objp->ref; |
|
| 308 | + print $invoicestatic->getNomUrl(1); |
|
| 309 | + print "</td>\n"; |
|
| 310 | + print "<td align=\"center\">"; |
|
| 311 | + print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 312 | + } |
|
| 313 | + else { |
|
| 314 | + $companystatic->id=$objp->socid; |
|
| 315 | + $companystatic->name=$objp->name; |
|
| 316 | + $companystatic->client=$objp->client; |
|
| 317 | + print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n"; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
| 321 | + print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
| 322 | + print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 323 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 324 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 325 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 326 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 327 | + print "</tr>\n"; |
|
| 328 | + |
|
| 329 | + $i++; |
|
| 330 | + $cumul_achat += $objp->buying_price; |
|
| 331 | + $cumul_vente += $objp->selling_price; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // affichage totaux marges |
|
| 336 | + |
|
| 337 | + $totalMargin = $cumul_vente - $cumul_achat; |
|
| 338 | + /*if ($totalMargin < 0) |
|
| 339 | 339 | { |
| 340 | 340 | $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
| 341 | 341 | $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
| 342 | 342 | } |
| 343 | 343 | else |
| 344 | 344 | {*/ |
| 345 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 346 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 347 | - //} |
|
| 348 | - |
|
| 349 | - print '<tr class="liste_total">'; |
|
| 350 | - if ($client) |
|
| 351 | - print '<td colspan=2>'; |
|
| 352 | - else |
|
| 353 | - print '<td>'; |
|
| 354 | - print $langs->trans('TotalMargin')."</td>"; |
|
| 355 | - print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
| 356 | - print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
| 357 | - print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
| 358 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 359 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 360 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 361 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 362 | - print "</tr>\n"; |
|
| 363 | - |
|
| 364 | - print "</table>"; |
|
| 345 | + $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 346 | + $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 347 | + //} |
|
| 348 | + |
|
| 349 | + print '<tr class="liste_total">'; |
|
| 350 | + if ($client) |
|
| 351 | + print '<td colspan=2>'; |
|
| 352 | + else |
|
| 353 | + print '<td>'; |
|
| 354 | + print $langs->trans('TotalMargin')."</td>"; |
|
| 355 | + print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
| 356 | + print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
| 357 | + print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
| 358 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 359 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 360 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 361 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 362 | + print "</tr>\n"; |
|
| 363 | + |
|
| 364 | + print "</table>"; |
|
| 365 | 365 | } |
| 366 | 366 | else |
| 367 | 367 | { |
| 368 | - dol_print_error($db); |
|
| 368 | + dol_print_error($db); |
|
| 369 | 369 | } |
| 370 | 370 | $db->free($result); |
| 371 | 371 | |
@@ -36,7 +36,9 @@ discard block |
||
| 36 | 36 | $TSelectedProducts = GETPOST('products', 'array'); |
| 37 | 37 | $TSelectedCats = GETPOST('categories', 'array'); |
| 38 | 38 | |
| 39 | -if (! empty($user->societe_id)) $socid=$user->societe_id; |
|
| 39 | +if (! empty($user->societe_id)) { |
|
| 40 | + $socid=$user->societe_id; |
|
| 41 | +} |
|
| 40 | 42 | $result = restrictedArea($user, 'societe','',''); |
| 41 | 43 | $result = restrictedArea($user,'margins'); |
| 42 | 44 | |
@@ -52,15 +54,22 @@ discard block |
||
| 52 | 54 | $offset = $limit * $page; |
| 53 | 55 | $pageprev = $page - 1; |
| 54 | 56 | $pagenext = $page + 1; |
| 55 | -if (! $sortfield) $sortfield="s.nom"; // Set here default search field |
|
| 56 | -if (! $sortorder) $sortorder="ASC"; |
|
| 57 | +if (! $sortfield) { |
|
| 58 | + $sortfield="s.nom"; |
|
| 59 | +} |
|
| 60 | +// Set here default search field |
|
| 61 | +if (! $sortorder) { |
|
| 62 | + $sortorder="ASC"; |
|
| 63 | +} |
|
| 57 | 64 | |
| 58 | 65 | $startdate=$enddate=''; |
| 59 | 66 | |
| 60 | -if (!empty($_POST['startdatemonth'])) |
|
| 67 | +if (!empty($_POST['startdatemonth'])) { |
|
| 61 | 68 | $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
| 62 | -if (!empty($_POST['enddatemonth'])) |
|
| 69 | +} |
|
| 70 | +if (!empty($_POST['enddatemonth'])) { |
|
| 63 | 71 | $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
| 72 | +} |
|
| 64 | 73 | |
| 65 | 74 | |
| 66 | 75 | /* |
@@ -104,11 +113,14 @@ discard block |
||
| 104 | 113 | print '</td></tr>'; |
| 105 | 114 | |
| 106 | 115 | $client = true; |
| 107 | - if (! $sortorder) $sortorder="DESC"; |
|
| 108 | - if (! $sortfield) $sortfield="f.datef"; |
|
| 116 | + if (! $sortorder) { |
|
| 117 | + $sortorder="DESC"; |
|
| 118 | + } |
|
| 119 | + if (! $sortfield) { |
|
| 120 | + $sortfield="f.datef"; |
|
| 121 | + } |
|
| 109 | 122 | } |
| 110 | -} |
|
| 111 | -else { |
|
| 123 | +} else { |
|
| 112 | 124 | print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
| 113 | 125 | print '<td class="maxwidthonsmartphone" colspan="4">'; |
| 114 | 126 | print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0); |
@@ -118,15 +130,16 @@ discard block |
||
| 118 | 130 | |
| 119 | 131 | $sortfield = GETPOST("sortfield",'alpha'); |
| 120 | 132 | $sortorder = GETPOST("sortorder",'alpha'); |
| 121 | -if (! $sortorder) $sortorder="ASC"; |
|
| 133 | +if (! $sortorder) { |
|
| 134 | + $sortorder="ASC"; |
|
| 135 | +} |
|
| 122 | 136 | if (! $sortfield) |
| 123 | 137 | { |
| 124 | 138 | if ($client) |
| 125 | 139 | { |
| 126 | 140 | $sortfield="f.datef"; |
| 127 | 141 | $sortorder="DESC"; |
| 128 | - } |
|
| 129 | - else |
|
| 142 | + } else |
|
| 130 | 143 | { |
| 131 | 144 | $sortfield="s.nom"; |
| 132 | 145 | $sortorder="ASC"; |
@@ -202,7 +215,9 @@ discard block |
||
| 202 | 215 | |
| 203 | 216 | $sql = "SELECT"; |
| 204 | 217 | $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
| 205 | -if ($client) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; |
|
| 218 | +if ($client) { |
|
| 219 | + $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; |
|
| 220 | +} |
|
| 206 | 221 | $sql.= " sum(d.total_ht) as selling_price,"; |
| 207 | 222 | // Note: qty and buy_price_ht is always positive (if not, your database may be corrupted, you can update this) |
| 208 | 223 | $sql.= " sum(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,"; |
@@ -214,10 +229,16 @@ discard block |
||
| 214 | 229 | $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; |
| 215 | 230 | } |
| 216 | 231 | |
| 217 | -if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 232 | +if (! $user->rights->societe->client->voir && ! $socid) { |
|
| 233 | + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 234 | +} |
|
| 218 | 235 | $sql.= " WHERE f.fk_soc = s.rowid"; |
| 219 | -if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; |
|
| 220 | -if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 236 | +if ($socid > 0) { |
|
| 237 | + $sql.= ' AND s.rowid = '.$socid; |
|
| 238 | +} |
|
| 239 | +if (!$user->rights->societe->client->voir && ! $socid) { |
|
| 240 | + $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 241 | +} |
|
| 221 | 242 | $sql.= " AND f.fk_statut > 0"; |
| 222 | 243 | $sql.= ' AND s.entity IN ('.getEntity('societe').')'; |
| 223 | 244 | $sql.= " AND d.fk_facture = f.rowid"; |
@@ -228,15 +249,21 @@ discard block |
||
| 228 | 249 | if(! empty($TSelectedCats)) { |
| 229 | 250 | $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
| 230 | 251 | } |
| 231 | -if (!empty($startdate)) |
|
| 232 | -$sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 233 | -if (!empty($enddate)) |
|
| 234 | -$sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 252 | +if (!empty($startdate)) { |
|
| 253 | + $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 254 | +} |
|
| 255 | +if (!empty($enddate)) { |
|
| 256 | + $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 257 | +} |
|
| 235 | 258 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 236 | -if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) |
|
| 237 | -$sql .= " AND d.buy_price_ht <> 0"; |
|
| 238 | -if ($client) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut"; |
|
| 239 | -else $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client"; |
|
| 259 | +if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) { |
|
| 260 | + $sql .= " AND d.buy_price_ht <> 0"; |
|
| 261 | +} |
|
| 262 | +if ($client) { |
|
| 263 | + $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut"; |
|
| 264 | +} else { |
|
| 265 | + $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client"; |
|
| 266 | +} |
|
| 240 | 267 | $sql.=$db->order($sortfield,$sortorder); |
| 241 | 268 | // TODO: calculate total to display then restore pagination |
| 242 | 269 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
@@ -250,10 +277,12 @@ discard block |
||
| 250 | 277 | print '<br>'; |
| 251 | 278 | print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
| 252 | 279 | |
| 253 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 254 | - $labelcostprice='BuyingPrice'; |
|
| 255 | - else // value is 'costprice' or 'pmp' |
|
| 280 | + if ($conf->global->MARGIN_TYPE == "1") { |
|
| 281 | + $labelcostprice='BuyingPrice'; |
|
| 282 | + } else { |
|
| 283 | + // value is 'costprice' or 'pmp' |
|
| 256 | 284 | $labelcostprice='CostPrice'; |
| 285 | + } |
|
| 257 | 286 | |
| 258 | 287 | $i = 0; |
| 259 | 288 | print "<table class=\"noborder\" width=\"100%\">"; |
@@ -262,16 +291,18 @@ discard block |
||
| 262 | 291 | if (! empty($client)) { |
| 263 | 292 | print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$socid,'',$sortfield,$sortorder); |
| 264 | 293 | print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); |
| 294 | + } else { |
|
| 295 | + print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 265 | 296 | } |
| 266 | - else |
|
| 267 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 268 | 297 | print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
| 269 | 298 | print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
| 270 | 299 | print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
| 271 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 272 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 273 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 274 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 300 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 301 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 302 | + } |
|
| 303 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 304 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 305 | + } |
|
| 275 | 306 | print "</tr>\n"; |
| 276 | 307 | |
| 277 | 308 | $cumul_achat = 0; |
@@ -293,8 +324,7 @@ discard block |
||
| 293 | 324 | { |
| 294 | 325 | $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
| 295 | 326 | $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
| 296 | - } |
|
| 297 | - else |
|
| 327 | + } else |
|
| 298 | 328 | { |
| 299 | 329 | $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
| 300 | 330 | $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
@@ -309,8 +339,7 @@ discard block |
||
| 309 | 339 | print "</td>\n"; |
| 310 | 340 | print "<td align=\"center\">"; |
| 311 | 341 | print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
| 312 | - } |
|
| 313 | - else { |
|
| 342 | + } else { |
|
| 314 | 343 | $companystatic->id=$objp->socid; |
| 315 | 344 | $companystatic->name=$objp->name; |
| 316 | 345 | $companystatic->client=$objp->client; |
@@ -320,10 +349,12 @@ discard block |
||
| 320 | 349 | print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
| 321 | 350 | print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
| 322 | 351 | print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
| 323 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 324 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 325 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 326 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 352 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 353 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 354 | + } |
|
| 355 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 356 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 357 | + } |
|
| 327 | 358 | print "</tr>\n"; |
| 328 | 359 | |
| 329 | 360 | $i++; |
@@ -347,23 +378,25 @@ discard block |
||
| 347 | 378 | //} |
| 348 | 379 | |
| 349 | 380 | print '<tr class="liste_total">'; |
| 350 | - if ($client) |
|
| 351 | - print '<td colspan=2>'; |
|
| 352 | - else |
|
| 353 | - print '<td>'; |
|
| 381 | + if ($client) { |
|
| 382 | + print '<td colspan=2>'; |
|
| 383 | + } else { |
|
| 384 | + print '<td>'; |
|
| 385 | + } |
|
| 354 | 386 | print $langs->trans('TotalMargin')."</td>"; |
| 355 | 387 | print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
| 356 | 388 | print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
| 357 | 389 | print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
| 358 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 359 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 360 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 361 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 390 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 391 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 392 | + } |
|
| 393 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 394 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 395 | + } |
|
| 362 | 396 | print "</tr>\n"; |
| 363 | 397 | |
| 364 | 398 | print "</table>"; |
| 365 | -} |
|
| 366 | -else |
|
| 399 | +} else |
|
| 367 | 400 | { |
| 368 | 401 | dol_print_error($db); |
| 369 | 402 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
| 27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
| 28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
| 28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
| 29 | 29 | |
| 30 | 30 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
| 31 | 31 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
@@ -36,35 +36,35 @@ discard block |
||
| 36 | 36 | $langs->loadLangs(array('companies', 'bills', 'products', 'margins')); |
| 37 | 37 | |
| 38 | 38 | // Security check |
| 39 | -$socid = GETPOST('socid','int'); |
|
| 39 | +$socid = GETPOST('socid', 'int'); |
|
| 40 | 40 | $TSelectedProducts = GETPOST('products', 'array'); |
| 41 | 41 | $TSelectedCats = GETPOST('categories', 'array'); |
| 42 | 42 | |
| 43 | -if (! empty($user->societe_id)) $socid=$user->societe_id; |
|
| 44 | -$result = restrictedArea($user, 'societe','',''); |
|
| 45 | -$result = restrictedArea($user,'margins'); |
|
| 43 | +if (!empty($user->societe_id)) $socid = $user->societe_id; |
|
| 44 | +$result = restrictedArea($user, 'societe', '', ''); |
|
| 45 | +$result = restrictedArea($user, 'margins'); |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | $mesg = ''; |
| 49 | 49 | |
| 50 | 50 | // Load variable for pagination |
| 51 | -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
|
| 52 | -$sortfield = GETPOST('sortfield','alpha'); |
|
| 53 | -$sortorder = GETPOST('sortorder','alpha'); |
|
| 54 | -$page = GETPOST('page','int'); |
|
| 51 | +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; |
|
| 52 | +$sortfield = GETPOST('sortfield', 'alpha'); |
|
| 53 | +$sortorder = GETPOST('sortorder', 'alpha'); |
|
| 54 | +$page = GETPOST('page', 'int'); |
|
| 55 | 55 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
| 56 | 56 | $offset = $limit * $page; |
| 57 | 57 | $pageprev = $page - 1; |
| 58 | 58 | $pagenext = $page + 1; |
| 59 | -if (! $sortfield) $sortfield="s.nom"; // Set here default search field |
|
| 60 | -if (! $sortorder) $sortorder="ASC"; |
|
| 59 | +if (!$sortfield) $sortfield = "s.nom"; // Set here default search field |
|
| 60 | +if (!$sortorder) $sortorder = "ASC"; |
|
| 61 | 61 | |
| 62 | -$startdate=$enddate=''; |
|
| 62 | +$startdate = $enddate = ''; |
|
| 63 | 63 | |
| 64 | 64 | if (!empty($_POST['startdatemonth'])) |
| 65 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 65 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 66 | 66 | if (!empty($_POST['enddatemonth'])) |
| 67 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 67 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | /* |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | |
| 74 | 74 | $companystatic = new Societe($db); |
| 75 | -$invoicestatic=new Facture($db); |
|
| 75 | +$invoicestatic = new Facture($db); |
|
| 76 | 76 | |
| 77 | 77 | $form = new Form($db); |
| 78 | 78 | |
| 79 | -llxHeader('',$langs->trans("Margins").' - '.$langs->trans("Clients")); |
|
| 79 | +llxHeader('', $langs->trans("Margins").' - '.$langs->trans("Clients")); |
|
| 80 | 80 | |
| 81 | -$text=$langs->trans("Margins"); |
|
| 81 | +$text = $langs->trans("Margins"); |
|
| 82 | 82 | //print load_fiche_titre($text); |
| 83 | 83 | |
| 84 | 84 | // Show tabs |
| 85 | -$head=marges_prepare_head($user); |
|
| 86 | -$titre=$langs->trans("Margins"); |
|
| 87 | -$picto='margin'; |
|
| 85 | +$head = marges_prepare_head($user); |
|
| 86 | +$titre = $langs->trans("Margins"); |
|
| 87 | +$picto = 'margin'; |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">'; |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | print '</td></tr>'; |
| 109 | 109 | |
| 110 | 110 | $client = true; |
| 111 | - if (! $sortorder) $sortorder="DESC"; |
|
| 112 | - if (! $sortfield) $sortfield="f.datef"; |
|
| 111 | + if (!$sortorder) $sortorder = "DESC"; |
|
| 112 | + if (!$sortfield) $sortfield = "f.datef"; |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | else { |
@@ -120,28 +120,28 @@ discard block |
||
| 120 | 120 | print '</td></tr>'; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | -$sortfield = GETPOST("sortfield",'alpha'); |
|
| 124 | -$sortorder = GETPOST("sortorder",'alpha'); |
|
| 125 | -if (! $sortorder) $sortorder="ASC"; |
|
| 126 | -if (! $sortfield) |
|
| 123 | +$sortfield = GETPOST("sortfield", 'alpha'); |
|
| 124 | +$sortorder = GETPOST("sortorder", 'alpha'); |
|
| 125 | +if (!$sortorder) $sortorder = "ASC"; |
|
| 126 | +if (!$sortfield) |
|
| 127 | 127 | { |
| 128 | 128 | if ($client) |
| 129 | 129 | { |
| 130 | - $sortfield="f.datef"; |
|
| 131 | - $sortorder="DESC"; |
|
| 130 | + $sortfield = "f.datef"; |
|
| 131 | + $sortorder = "DESC"; |
|
| 132 | 132 | } |
| 133 | 133 | else |
| 134 | 134 | { |
| 135 | - $sortfield="s.nom"; |
|
| 136 | - $sortorder="ASC"; |
|
| 135 | + $sortfield = "s.nom"; |
|
| 136 | + $sortorder = "ASC"; |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Products |
| 141 | -$TRes = $form->select_produits_list('','','',20,0,'',1,2,1,0,'', 1); |
|
| 141 | +$TRes = $form->select_produits_list('', '', '', 20, 0, '', 1, 2, 1, 0, '', 1); |
|
| 142 | 142 | |
| 143 | 143 | $TProducts = array(); |
| 144 | -foreach($TRes as $prod) { |
|
| 144 | +foreach ($TRes as $prod) { |
|
| 145 | 145 | $TProducts[$prod['key']] = $prod['label']; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | print '</td></tr>'; |
| 186 | 186 | |
| 187 | 187 | // Margin Rate |
| 188 | -if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 188 | +if (!empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 189 | 189 | print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
| 190 | 190 | print '<span id="marginRate"></span>'; // set by jquery (see below) |
| 191 | 191 | print '</td></tr>'; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Mark Rate |
| 195 | -if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 195 | +if (!empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 196 | 196 | print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
| 197 | 197 | print '<span id="markRate"></span>'; // set by jquery (see below) |
| 198 | 198 | print '</td></tr>'; |
@@ -205,43 +205,43 @@ discard block |
||
| 205 | 205 | print '</form>'; |
| 206 | 206 | |
| 207 | 207 | $sql = "SELECT"; |
| 208 | -$sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
|
| 209 | -if ($client) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; |
|
| 210 | -$sql.= " sum(d.total_ht) as selling_price,"; |
|
| 208 | +$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; |
|
| 209 | +if ($client) $sql .= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,"; |
|
| 210 | +$sql .= " sum(d.total_ht) as selling_price,"; |
|
| 211 | 211 | // Note: qty and buy_price_ht is always positive (if not, your database may be corrupted, you can update this) |
| 212 | -$sql.= " sum(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,"; |
|
| 213 | -$sql.= " sum(".$db->ifsql('d.total_ht < 0','-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))','d.total_ht - (d.buy_price_ht * d.qty)').") as marge"; |
|
| 214 | -$sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 215 | -$sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 216 | -$sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 217 | -if(! empty($TSelectedCats)) { |
|
| 212 | +$sql .= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; |
|
| 213 | +$sql .= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge"; |
|
| 214 | +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
| 215 | +$sql .= ", ".MAIN_DB_PREFIX."facture as f"; |
|
| 216 | +$sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; |
|
| 217 | +if (!empty($TSelectedCats)) { |
|
| 218 | 218 | $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | -if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 222 | -$sql.= " WHERE f.fk_soc = s.rowid"; |
|
| 223 | -if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; |
|
| 224 | -if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 225 | -$sql.= " AND f.fk_statut > 0"; |
|
| 226 | -$sql.= ' AND s.entity IN ('.getEntity('societe').')'; |
|
| 227 | -$sql.= " AND d.fk_facture = f.rowid"; |
|
| 228 | -$sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
|
| 229 | -if(! empty($TSelectedProducts)) { |
|
| 230 | - $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')'; |
|
| 221 | +if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 222 | +$sql .= " WHERE f.fk_soc = s.rowid"; |
|
| 223 | +if ($socid > 0) $sql .= ' AND s.rowid = '.$socid; |
|
| 224 | +if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
| 225 | +$sql .= " AND f.fk_statut > 0"; |
|
| 226 | +$sql .= ' AND s.entity IN ('.getEntity('societe').')'; |
|
| 227 | +$sql .= " AND d.fk_facture = f.rowid"; |
|
| 228 | +$sql .= " AND (d.product_type = 0 OR d.product_type = 1)"; |
|
| 229 | +if (!empty($TSelectedProducts)) { |
|
| 230 | + $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts).')'; |
|
| 231 | 231 | } |
| 232 | -if(! empty($TSelectedCats)) { |
|
| 233 | - $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
| 232 | +if (!empty($TSelectedCats)) { |
|
| 233 | + $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats).')'; |
|
| 234 | 234 | } |
| 235 | 235 | if (!empty($startdate)) |
| 236 | -$sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 236 | +$sql .= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 237 | 237 | if (!empty($enddate)) |
| 238 | -$sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 238 | +$sql .= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 239 | 239 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 240 | 240 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) |
| 241 | 241 | $sql .= " AND d.buy_price_ht <> 0"; |
| 242 | -if ($client) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut"; |
|
| 243 | -else $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client"; |
|
| 244 | -$sql.=$db->order($sortfield,$sortorder); |
|
| 242 | +if ($client) $sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut"; |
|
| 243 | +else $sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client"; |
|
| 244 | +$sql .= $db->order($sortfield, $sortorder); |
|
| 245 | 245 | // TODO: calculate total to display then restore pagination |
| 246 | 246 | //$sql.= $db->plimit($conf->liste_limit +1, $offset); |
| 247 | 247 | |
@@ -255,33 +255,33 @@ discard block |
||
| 255 | 255 | print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
| 256 | 256 | |
| 257 | 257 | if ($conf->global->MARGIN_TYPE == "1") |
| 258 | - $labelcostprice='BuyingPrice'; |
|
| 258 | + $labelcostprice = 'BuyingPrice'; |
|
| 259 | 259 | else // value is 'costprice' or 'pmp' |
| 260 | - $labelcostprice='CostPrice'; |
|
| 260 | + $labelcostprice = 'CostPrice'; |
|
| 261 | 261 | |
| 262 | 262 | $i = 0; |
| 263 | 263 | print "<table class=\"noborder\" width=\"100%\">"; |
| 264 | 264 | |
| 265 | 265 | print '<tr class="liste_titre">'; |
| 266 | - if (! empty($client)) { |
|
| 267 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 268 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); |
|
| 266 | + if (!empty($client)) { |
|
| 267 | + print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", "&socid=".$socid, '', $sortfield, $sortorder); |
|
| 268 | + print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", "&socid=".$socid, 'align="center"', $sortfield, $sortorder); |
|
| 269 | 269 | } |
| 270 | 270 | else |
| 271 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 272 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 273 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 274 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 275 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 276 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 277 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 278 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 271 | + print_liste_field_titre("Customer", $_SERVER["PHP_SELF"], "s.nom", "", "&socid=".$socid, '', $sortfield, $sortorder); |
|
| 272 | + print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", "&socid=".$socid, 'align="right"', $sortfield, $sortorder); |
|
| 273 | + print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", "&socid=".$socid, 'align="right"', $sortfield, $sortorder); |
|
| 274 | + print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", "&socid=".$socid, 'align="right"', $sortfield, $sortorder); |
|
| 275 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 276 | + print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", "&socid=".$socid, 'align="right"', $sortfield, $sortorder); |
|
| 277 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 278 | + print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", "&socid=".$socid, 'align="right"', $sortfield, $sortorder); |
|
| 279 | 279 | print "</tr>\n"; |
| 280 | 280 | |
| 281 | 281 | $cumul_achat = 0; |
| 282 | 282 | $cumul_vente = 0; |
| 283 | 283 | |
| 284 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 284 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 285 | 285 | |
| 286 | 286 | if ($num > 0) |
| 287 | 287 | { |
@@ -295,39 +295,39 @@ discard block |
||
| 295 | 295 | |
| 296 | 296 | if ($marge < 0) |
| 297 | 297 | { |
| 298 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 299 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 298 | + $marginRate = ($pa != 0) ?-1 * (100 * $marge / $pa) : ''; |
|
| 299 | + $markRate = ($pv != 0) ?-1 * (100 * $marge / $pv) : ''; |
|
| 300 | 300 | } |
| 301 | 301 | else |
| 302 | 302 | { |
| 303 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 304 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 303 | + $marginRate = ($pa != 0) ? (100 * $marge / $pa) : ''; |
|
| 304 | + $markRate = ($pv != 0) ? (100 * $marge / $pv) : ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | print '<tr class="oddeven">'; |
| 308 | 308 | if ($client) { |
| 309 | 309 | print '<td>'; |
| 310 | - $invoicestatic->id=$objp->facid; |
|
| 311 | - $invoicestatic->ref=$objp->ref; |
|
| 310 | + $invoicestatic->id = $objp->facid; |
|
| 311 | + $invoicestatic->ref = $objp->ref; |
|
| 312 | 312 | print $invoicestatic->getNomUrl(1); |
| 313 | 313 | print "</td>\n"; |
| 314 | 314 | print "<td align=\"center\">"; |
| 315 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 315 | + print dol_print_date($db->jdate($objp->datef), 'day')."</td>"; |
|
| 316 | 316 | } |
| 317 | 317 | else { |
| 318 | - $companystatic->id=$objp->socid; |
|
| 319 | - $companystatic->name=$objp->name; |
|
| 320 | - $companystatic->client=$objp->client; |
|
| 321 | - print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n"; |
|
| 318 | + $companystatic->id = $objp->socid; |
|
| 319 | + $companystatic->name = $objp->name; |
|
| 320 | + $companystatic->client = $objp->client; |
|
| 321 | + print "<td>".$companystatic->getNomUrl(1, 'margin')."</td>\n"; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
| 325 | 325 | print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
| 326 | 326 | print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
| 327 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 328 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 329 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 330 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 327 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 328 | + print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 329 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 330 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 331 | 331 | print "</tr>\n"; |
| 332 | 332 | |
| 333 | 333 | $i++; |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | } |
| 347 | 347 | else |
| 348 | 348 | {*/ |
| 349 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 350 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 349 | + $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : ''; |
|
| 350 | + $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : ''; |
|
| 351 | 351 | //} |
| 352 | 352 | |
| 353 | 353 | print '<tr class="liste_total">'; |
@@ -359,10 +359,10 @@ discard block |
||
| 359 | 359 | print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
| 360 | 360 | print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
| 361 | 361 | print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
| 362 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 363 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 364 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 365 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 362 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 363 | + print "<td align=\"right\">".(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 364 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 365 | + print "<td align=\"right\">".(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 366 | 366 | print "</tr>\n"; |
| 367 | 367 | |
| 368 | 368 | print "</table>"; |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | });*/ |
| 382 | 382 | |
| 383 | 383 | $("#totalMargin").html("'.price($totalMargin, null, null, null, null, $rounding).'"); |
| 384 | - $("#marginRate").html("'.(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%").'"); |
|
| 385 | - $("#markRate").html("'.(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%").'"); |
|
| 384 | + $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price($marginRate, null, null, null, null, $rounding)."%").'"); |
|
| 385 | + $("#markRate").html("'.(($markRate === '') ? 'n/a' : price($markRate, null, null, null, null, $rounding)."%").'"); |
|
| 386 | 386 | }); |
| 387 | 387 | </script> |
| 388 | 388 | '; |
@@ -201,115 +201,115 @@ |
||
| 201 | 201 | $nbtotalofrecords = ''; |
| 202 | 202 | if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { |
| 203 | 203 | |
| 204 | - dol_syslog(__FILE__, LOG_DEBUG); |
|
| 205 | - $result = $db->query($sql); |
|
| 206 | - $nbtotalofrecords = $db->num_rows($result); |
|
| 207 | - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
| 208 | - { |
|
| 209 | - $page = 0; |
|
| 210 | - $offset = 0; |
|
| 211 | - } |
|
| 204 | + dol_syslog(__FILE__, LOG_DEBUG); |
|
| 205 | + $result = $db->query($sql); |
|
| 206 | + $nbtotalofrecords = $db->num_rows($result); |
|
| 207 | + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
| 208 | + { |
|
| 209 | + $page = 0; |
|
| 210 | + $offset = 0; |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $sql .= $db->plimit($limit+1, $offset); |
| 215 | 215 | |
| 216 | 216 | $result = $db->query($sql); |
| 217 | 217 | if ($result) { |
| 218 | - $num = $db->num_rows($result); |
|
| 218 | + $num = $db->num_rows($result); |
|
| 219 | 219 | |
| 220 | - print '<br>'; |
|
| 221 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); |
|
| 220 | + print '<br>'; |
|
| 221 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); |
|
| 222 | 222 | |
| 223 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 224 | - $labelcostprice='BuyingPrice'; |
|
| 225 | - else // value is 'costprice' or 'pmp' |
|
| 226 | - $labelcostprice='CostPrice'; |
|
| 223 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 224 | + $labelcostprice='BuyingPrice'; |
|
| 225 | + else // value is 'costprice' or 'pmp' |
|
| 226 | + $labelcostprice='CostPrice'; |
|
| 227 | 227 | |
| 228 | - $moreforfilter=''; |
|
| 228 | + $moreforfilter=''; |
|
| 229 | 229 | |
| 230 | - $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; |
|
| 231 | - //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields |
|
| 232 | - //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); |
|
| 233 | - $selectedfields=''; |
|
| 230 | + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; |
|
| 231 | + //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields |
|
| 232 | + //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); |
|
| 233 | + $selectedfields=''; |
|
| 234 | 234 | |
| 235 | 235 | print '<div class="div-table-responsive">'; |
| 236 | 236 | print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; |
| 237 | 237 | |
| 238 | - print '<tr class="liste_titre liste_titre_search">'; |
|
| 239 | - print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>'; |
|
| 240 | - print '<td></td>'; |
|
| 241 | - print '<td></td>'; |
|
| 242 | - print '<td></td>'; |
|
| 243 | - print '<td></td>'; |
|
| 244 | - print '<td></td>'; |
|
| 238 | + print '<tr class="liste_titre liste_titre_search">'; |
|
| 239 | + print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>'; |
|
| 240 | + print '<td></td>'; |
|
| 241 | + print '<td></td>'; |
|
| 242 | + print '<td></td>'; |
|
| 243 | + print '<td></td>'; |
|
| 244 | + print '<td></td>'; |
|
| 245 | 245 | print '<td class="liste_titre" align="middle">'; |
| 246 | 246 | $searchpitco=$form->showFilterButtons(); |
| 247 | 247 | print $searchpitco; |
| 248 | 248 | print '</td>'; |
| 249 | - print "</tr>\n"; |
|
| 250 | - |
|
| 251 | - print '<tr class="liste_titre">'; |
|
| 252 | - print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder); |
|
| 253 | - print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder); |
|
| 254 | - print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 255 | - print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 256 | - print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 257 | - print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 258 | - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch '); |
|
| 259 | - print "</tr>\n"; |
|
| 249 | + print "</tr>\n"; |
|
| 250 | + |
|
| 251 | + print '<tr class="liste_titre">'; |
|
| 252 | + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder); |
|
| 253 | + print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder); |
|
| 254 | + print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 255 | + print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 256 | + print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 257 | + print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 258 | + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch '); |
|
| 259 | + print "</tr>\n"; |
|
| 260 | 260 | |
| 261 | 261 | $i=0; |
| 262 | - while ($i < min($num, $limit)) |
|
| 263 | - { |
|
| 264 | - $objp = $db->fetch_object($result); |
|
| 265 | - |
|
| 266 | - print '<tr class="oddeven">'; |
|
| 267 | - print '<td>'; |
|
| 268 | - $result_inner = $invoicestatic->fetch($objp->invoiceid); |
|
| 269 | - if ($result_inner < 0) { |
|
| 270 | - setEventMessages($invoicestatic->error, null, 'errors'); |
|
| 271 | - } else { |
|
| 272 | - print $invoicestatic->getNomUrl(1); |
|
| 273 | - } |
|
| 274 | - print '</td>'; |
|
| 275 | - print '<td>'; |
|
| 276 | - if (! empty($objp->fk_product)) { |
|
| 277 | - $result_inner = $productstatic->fetch($objp->fk_product); |
|
| 278 | - if ($result_inner < 0) { |
|
| 279 | - setEventMessages($productstatic->error, null, 'errors'); |
|
| 280 | - } else { |
|
| 281 | - print $productstatic->getNomUrl(1); |
|
| 282 | - } |
|
| 283 | - } else { |
|
| 284 | - print $objp->label; |
|
| 285 | - print ' '; |
|
| 286 | - print $objp->description; |
|
| 287 | - } |
|
| 288 | - print '</td>'; |
|
| 289 | - print '<td align="right">'; |
|
| 290 | - print price($objp->subprice); |
|
| 291 | - print '</td>'; |
|
| 292 | - print '<td align="right">'; |
|
| 293 | - print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">'; |
|
| 294 | - print '</td>'; |
|
| 295 | - print '<td align="right">'; |
|
| 296 | - print $objp->qty; |
|
| 297 | - print '</td>'; |
|
| 298 | - print '<td align="right">'; |
|
| 299 | - print price($objp->total_ht); |
|
| 300 | - print '</td>'; |
|
| 301 | - print '<td></td>'; |
|
| 302 | - |
|
| 303 | - print "</tr>\n"; |
|
| 304 | - |
|
| 305 | - $i ++; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - print "</table>"; |
|
| 309 | - |
|
| 310 | - print "</div>"; |
|
| 262 | + while ($i < min($num, $limit)) |
|
| 263 | + { |
|
| 264 | + $objp = $db->fetch_object($result); |
|
| 265 | + |
|
| 266 | + print '<tr class="oddeven">'; |
|
| 267 | + print '<td>'; |
|
| 268 | + $result_inner = $invoicestatic->fetch($objp->invoiceid); |
|
| 269 | + if ($result_inner < 0) { |
|
| 270 | + setEventMessages($invoicestatic->error, null, 'errors'); |
|
| 271 | + } else { |
|
| 272 | + print $invoicestatic->getNomUrl(1); |
|
| 273 | + } |
|
| 274 | + print '</td>'; |
|
| 275 | + print '<td>'; |
|
| 276 | + if (! empty($objp->fk_product)) { |
|
| 277 | + $result_inner = $productstatic->fetch($objp->fk_product); |
|
| 278 | + if ($result_inner < 0) { |
|
| 279 | + setEventMessages($productstatic->error, null, 'errors'); |
|
| 280 | + } else { |
|
| 281 | + print $productstatic->getNomUrl(1); |
|
| 282 | + } |
|
| 283 | + } else { |
|
| 284 | + print $objp->label; |
|
| 285 | + print ' '; |
|
| 286 | + print $objp->description; |
|
| 287 | + } |
|
| 288 | + print '</td>'; |
|
| 289 | + print '<td align="right">'; |
|
| 290 | + print price($objp->subprice); |
|
| 291 | + print '</td>'; |
|
| 292 | + print '<td align="right">'; |
|
| 293 | + print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">'; |
|
| 294 | + print '</td>'; |
|
| 295 | + print '<td align="right">'; |
|
| 296 | + print $objp->qty; |
|
| 297 | + print '</td>'; |
|
| 298 | + print '<td align="right">'; |
|
| 299 | + print price($objp->total_ht); |
|
| 300 | + print '</td>'; |
|
| 301 | + print '<td></td>'; |
|
| 302 | + |
|
| 303 | + print "</tr>\n"; |
|
| 304 | + |
|
| 305 | + $i ++; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + print "</table>"; |
|
| 309 | + |
|
| 310 | + print "</div>"; |
|
| 311 | 311 | } else { |
| 312 | - dol_print_error($db); |
|
| 312 | + dol_print_error($db); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -48,8 +48,12 @@ discard block |
||
| 48 | 48 | $offset = $limit * $page; |
| 49 | 49 | $pageprev = $page - 1; |
| 50 | 50 | $pagenext = $page + 1; |
| 51 | -if (! $sortorder) $sortorder = "DESC"; |
|
| 52 | -if (! $sortfield) $sortfield = 'f.ref'; |
|
| 51 | +if (! $sortorder) { |
|
| 52 | + $sortorder = "DESC"; |
|
| 53 | +} |
|
| 54 | +if (! $sortfield) { |
|
| 55 | + $sortfield = 'f.ref'; |
|
| 56 | +} |
|
| 53 | 57 | |
| 54 | 58 | $startdate = $enddate = ''; |
| 55 | 59 | |
@@ -78,7 +82,9 @@ discard block |
||
| 78 | 82 | |
| 79 | 83 | $parameters=array(); |
| 80 | 84 | $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
| 81 | -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
| 85 | +if ($reshook < 0) { |
|
| 86 | + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
| 87 | +} |
|
| 82 | 88 | |
| 83 | 89 | if (empty($reshook)) |
| 84 | 90 | { |
@@ -108,9 +114,11 @@ discard block |
||
| 108 | 114 | } |
| 109 | 115 | |
| 110 | 116 | // Purge search criteria |
| 111 | - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers |
|
| 117 | + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) { |
|
| 118 | + // All tests are required to be compatible with all browsers |
|
| 112 | 119 | { |
| 113 | 120 | $search_ref=''; |
| 121 | + } |
|
| 114 | 122 | $search_array_options=array(); |
| 115 | 123 | } |
| 116 | 124 | |
@@ -146,12 +154,24 @@ discard block |
||
| 146 | 154 | // print_fiche_titre($text); |
| 147 | 155 | |
| 148 | 156 | $param=''; |
| 149 | -if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
|
| 150 | -if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
| 151 | -if ($search_ref != '') $param.='&search_ref='.urlencode($search_ref); |
|
| 152 | -if (! empty($startdate)) $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int'); |
|
| 153 | -if (! empty($enddate)) $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int'); |
|
| 154 | -if ($optioncss != '') $param.='&optioncss='.$optioncss; |
|
| 157 | +if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { |
|
| 158 | + $param.='&contextpage='.$contextpage; |
|
| 159 | +} |
|
| 160 | +if ($limit > 0 && $limit != $conf->liste_limit) { |
|
| 161 | + $param.='&limit='.$limit; |
|
| 162 | +} |
|
| 163 | +if ($search_ref != '') { |
|
| 164 | + $param.='&search_ref='.urlencode($search_ref); |
|
| 165 | +} |
|
| 166 | +if (! empty($startdate)) { |
|
| 167 | + $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int'); |
|
| 168 | +} |
|
| 169 | +if (! empty($enddate)) { |
|
| 170 | + $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int'); |
|
| 171 | +} |
|
| 172 | +if ($optioncss != '') { |
|
| 173 | + $param.='&optioncss='.$optioncss; |
|
| 174 | +} |
|
| 155 | 175 | |
| 156 | 176 | // Show tabs |
| 157 | 177 | $head = marges_prepare_head($user); |
@@ -192,9 +212,15 @@ discard block |
||
| 192 | 212 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid"; |
| 193 | 213 | $sql .= " WHERE f.fk_statut > 0"; |
| 194 | 214 | $sql .= " AND f.entity IN (" . getEntity('invoice') . ") "; |
| 195 | -if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'"; |
|
| 196 | -if (! empty($enddate)) $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'"; |
|
| 197 | -if ($search_ref) $sql.=natural_search('f.ref', $search_ref); |
|
| 215 | +if (! empty($startdate)) { |
|
| 216 | + $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'"; |
|
| 217 | +} |
|
| 218 | +if (! empty($enddate)) { |
|
| 219 | + $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'"; |
|
| 220 | +} |
|
| 221 | +if ($search_ref) { |
|
| 222 | + $sql.=natural_search('f.ref', $search_ref); |
|
| 223 | +} |
|
| 198 | 224 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 199 | 225 | $sql .= $db->order($sortfield, $sortorder); |
| 200 | 226 | |
@@ -204,9 +230,11 @@ discard block |
||
| 204 | 230 | dol_syslog(__FILE__, LOG_DEBUG); |
| 205 | 231 | $result = $db->query($sql); |
| 206 | 232 | $nbtotalofrecords = $db->num_rows($result); |
| 207 | - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
| 233 | + if (($page * $limit) > $nbtotalofrecords) { |
|
| 234 | + // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
| 208 | 235 | { |
| 209 | 236 | $page = 0; |
| 237 | + } |
|
| 210 | 238 | $offset = 0; |
| 211 | 239 | } |
| 212 | 240 | } |
@@ -220,10 +248,12 @@ discard block |
||
| 220 | 248 | print '<br>'; |
| 221 | 249 | print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); |
| 222 | 250 | |
| 223 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 224 | - $labelcostprice='BuyingPrice'; |
|
| 225 | - else // value is 'costprice' or 'pmp' |
|
| 251 | + if ($conf->global->MARGIN_TYPE == "1") { |
|
| 252 | + $labelcostprice='BuyingPrice'; |
|
| 253 | + } else { |
|
| 254 | + // value is 'costprice' or 'pmp' |
|
| 226 | 255 | $labelcostprice='CostPrice'; |
| 256 | + } |
|
| 227 | 257 | |
| 228 | 258 | $moreforfilter=''; |
| 229 | 259 | |
@@ -26,44 +26,44 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
| 28 | 28 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
| 29 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
| 29 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
| 30 | 30 | |
| 31 | -require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; |
|
| 32 | -require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; |
|
| 33 | -require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
| 34 | -require_once DOL_DOCUMENT_ROOT . '/margin/lib/margins.lib.php'; |
|
| 31 | +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 32 | +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 33 | +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 34 | +require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php'; |
|
| 35 | 35 | |
| 36 | 36 | // Load translation files required by the page |
| 37 | 37 | $langs->loadLangs(array('companies', 'bills', 'products', 'margins')); |
| 38 | 38 | |
| 39 | -$action = GETPOST('action','alpha'); |
|
| 40 | -$massaction = GETPOST('massaction','alpha'); |
|
| 39 | +$action = GETPOST('action', 'alpha'); |
|
| 40 | +$massaction = GETPOST('massaction', 'alpha'); |
|
| 41 | 41 | $toselect = GETPOST('toselect', 'array'); |
| 42 | -$contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'margindetail'; // To manage different context of search |
|
| 43 | -$backtopage = GETPOST('backtopage','alpha'); |
|
| 44 | -$optioncss = GETPOST('optioncss','alpha'); |
|
| 42 | +$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'margindetail'; // To manage different context of search |
|
| 43 | +$backtopage = GETPOST('backtopage', 'alpha'); |
|
| 44 | +$optioncss = GETPOST('optioncss', 'alpha'); |
|
| 45 | 45 | |
| 46 | 46 | // Load variable for pagination |
| 47 | -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
|
| 48 | -$sortfield = GETPOST('sortfield','alpha'); |
|
| 49 | -$sortorder = GETPOST('sortorder','alpha'); |
|
| 50 | -$page = GETPOST('page','int'); |
|
| 47 | +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; |
|
| 48 | +$sortfield = GETPOST('sortfield', 'alpha'); |
|
| 49 | +$sortorder = GETPOST('sortorder', 'alpha'); |
|
| 50 | +$page = GETPOST('page', 'int'); |
|
| 51 | 51 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
| 52 | 52 | $offset = $limit * $page; |
| 53 | 53 | $pageprev = $page - 1; |
| 54 | 54 | $pagenext = $page + 1; |
| 55 | -if (! $sortorder) $sortorder = "DESC"; |
|
| 56 | -if (! $sortfield) $sortfield = 'f.ref'; |
|
| 55 | +if (!$sortorder) $sortorder = "DESC"; |
|
| 56 | +if (!$sortfield) $sortfield = 'f.ref'; |
|
| 57 | 57 | |
| 58 | 58 | $startdate = $enddate = ''; |
| 59 | 59 | |
| 60 | 60 | $startdate = dol_mktime(0, 0, 0, GETPOST('startdatemonth', 'int'), GETPOST('startdateday', 'int'), GETPOST('startdateyear', 'int')); |
| 61 | 61 | $enddate = dol_mktime(23, 59, 59, GETPOST('enddatemonth', 'int'), GETPOST('enddateday', 'int'), GETPOST('enddateyear', 'int')); |
| 62 | 62 | |
| 63 | -$search_ref = GETPOST('search_ref','alpha'); |
|
| 63 | +$search_ref = GETPOST('search_ref', 'alpha'); |
|
| 64 | 64 | |
| 65 | 65 | // Security check |
| 66 | -$result=restrictedArea($user,'margins'); |
|
| 66 | +$result = restrictedArea($user, 'margins'); |
|
| 67 | 67 | |
| 68 | 68 | // Both test are required to be compatible with all browsers |
| 69 | 69 | if (GETPOST("button_search_x") || GETPOST("button_search")) { |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | * Actions |
| 78 | 78 | */ |
| 79 | 79 | |
| 80 | -if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; } |
|
| 81 | -if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } |
|
| 80 | +if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } |
|
| 81 | +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } |
|
| 82 | 82 | |
| 83 | -$parameters=array(); |
|
| 84 | -$reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
| 83 | +$parameters = array(); |
|
| 84 | +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
| 85 | 85 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
| 86 | 86 | |
| 87 | 87 | if (empty($reshook)) |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | if ($action == 'update') { |
| 93 | 93 | $datapost = $_POST; |
| 94 | 94 | |
| 95 | - foreach ( $datapost as $key => $value ) { |
|
| 95 | + foreach ($datapost as $key => $value) { |
|
| 96 | 96 | if (strpos($key, 'buyingprice_') !== false) { |
| 97 | 97 | $tmp_array = explode('_', $key); |
| 98 | 98 | if (count($tmp_array) > 0) { |
| 99 | 99 | $invoicedet_id = $tmp_array[1]; |
| 100 | - if (! empty($invoicedet_id)) { |
|
| 101 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facturedet'; |
|
| 102 | - $sql .= ' SET buy_price_ht=\'' . price2num($value) . '\''; |
|
| 103 | - $sql .= ' WHERE rowid=' . $invoicedet_id; |
|
| 100 | + if (!empty($invoicedet_id)) { |
|
| 101 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facturedet'; |
|
| 102 | + $sql .= ' SET buy_price_ht=\''.price2num($value).'\''; |
|
| 103 | + $sql .= ' WHERE rowid='.$invoicedet_id; |
|
| 104 | 104 | $result = $db->query($sql); |
| 105 | 105 | if (!$result) { |
| 106 | 106 | setEventMessages($db->lasterror, null, 'errors'); |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // Purge search criteria |
| 115 | - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers |
|
| 115 | + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers |
|
| 116 | 116 | { |
| 117 | - $search_ref=''; |
|
| 118 | - $search_array_options=array(); |
|
| 117 | + $search_ref = ''; |
|
| 118 | + $search_array_options = array(); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Mass actions |
@@ -149,34 +149,34 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | // print_fiche_titre($text); |
| 151 | 151 | |
| 152 | -$param=''; |
|
| 153 | -if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
|
| 154 | -if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
| 155 | -if ($search_ref != '') $param.='&search_ref='.urlencode($search_ref); |
|
| 156 | -if (! empty($startdate)) $param .= '&startdatemonth=' . GETPOST('startdatemonth', 'int') . '&startdateday=' . GETPOST('startdateday', 'int') . '&startdateyear=' . GETPOST('startdateyear', 'int'); |
|
| 157 | -if (! empty($enddate)) $param .= '&enddatemonth=' . GETPOST('enddatemonth', 'int') . '&enddateday=' . GETPOST('enddateday', 'int') . '&enddateyear=' . GETPOST('enddateyear', 'int'); |
|
| 158 | -if ($optioncss != '') $param.='&optioncss='.$optioncss; |
|
| 152 | +$param = ''; |
|
| 153 | +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; |
|
| 154 | +if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; |
|
| 155 | +if ($search_ref != '') $param .= '&search_ref='.urlencode($search_ref); |
|
| 156 | +if (!empty($startdate)) $param .= '&startdatemonth='.GETPOST('startdatemonth', 'int').'&startdateday='.GETPOST('startdateday', 'int').'&startdateyear='.GETPOST('startdateyear', 'int'); |
|
| 157 | +if (!empty($enddate)) $param .= '&enddatemonth='.GETPOST('enddatemonth', 'int').'&enddateday='.GETPOST('enddateday', 'int').'&enddateyear='.GETPOST('enddateyear', 'int'); |
|
| 158 | +if ($optioncss != '') $param .= '&optioncss='.$optioncss; |
|
| 159 | 159 | |
| 160 | 160 | // Show tabs |
| 161 | 161 | $head = marges_prepare_head($user); |
| 162 | 162 | $picto = 'margin'; |
| 163 | 163 | |
| 164 | -print '<form method="post" name="sel" action="' . $_SERVER['PHP_SELF'] . '">'; |
|
| 164 | +print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">'; |
|
| 165 | 165 | |
| 166 | 166 | dol_fiche_head($head, $langs->trans('checkMargins'), $title, 0, $picto); |
| 167 | 167 | |
| 168 | 168 | print '<table class="border" width="100%">'; |
| 169 | 169 | |
| 170 | -print '<tr><td class="titlefield">' . $langs->trans('DateStart') . ' (' . $langs->trans("DateValidation") . ')</td>'; |
|
| 170 | +print '<tr><td class="titlefield">'.$langs->trans('DateStart').' ('.$langs->trans("DateValidation").')</td>'; |
|
| 171 | 171 | print '<td>'; |
| 172 | 172 | print $form->selectDate($startdate, 'startdate', '', '', 1, "sel", 1, 1); |
| 173 | 173 | print '</td>'; |
| 174 | -print '<td>' . $langs->trans('DateEnd') . ' (' . $langs->trans("DateValidation") . ')</td>'; |
|
| 174 | +print '<td>'.$langs->trans('DateEnd').' ('.$langs->trans("DateValidation").')</td>'; |
|
| 175 | 175 | print '<td>'; |
| 176 | 176 | print $form->selectDate($enddate, 'enddate', '', '', 1, "sel", 1, 1); |
| 177 | 177 | print '</td>'; |
| 178 | 178 | print '<td style="text-align: center;">'; |
| 179 | -print '<input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans('Refresh')) . '" name="button_search" />'; |
|
| 179 | +print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Refresh')).'" name="button_search" />'; |
|
| 180 | 180 | print '</td>'; |
| 181 | 181 | print '</tr>'; |
| 182 | 182 | print "</table>"; |
@@ -184,21 +184,21 @@ discard block |
||
| 184 | 184 | dol_fiche_end(); |
| 185 | 185 | |
| 186 | 186 | |
| 187 | -$arrayfields=array(); |
|
| 188 | -$massactionbutton=''; |
|
| 187 | +$arrayfields = array(); |
|
| 188 | +$massactionbutton = ''; |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | $sql = "SELECT"; |
| 192 | 192 | $sql .= " f.ref, f.rowid as invoiceid, d.rowid as invoicedetid, d.buy_price_ht, d.total_ht, d.subprice, d.label, d.description , d.qty"; |
| 193 | 193 | $sql .= " ,d.fk_product"; |
| 194 | -$sql .= " FROM " . MAIN_DB_PREFIX . "facture as f "; |
|
| 195 | -$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as d ON d.fk_facture = f.rowid"; |
|
| 196 | -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON d.fk_product = p.rowid"; |
|
| 194 | +$sql .= " FROM ".MAIN_DB_PREFIX."facture as f "; |
|
| 195 | +$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as d ON d.fk_facture = f.rowid"; |
|
| 196 | +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid"; |
|
| 197 | 197 | $sql .= " WHERE f.fk_statut > 0"; |
| 198 | -$sql .= " AND f.entity IN (" . getEntity('invoice') . ") "; |
|
| 199 | -if (! empty($startdate)) $sql .= " AND f.datef >= '" . $db->idate($startdate) . "'"; |
|
| 200 | -if (! empty($enddate)) $sql .= " AND f.datef <= '" . $db->idate($enddate) . "'"; |
|
| 201 | -if ($search_ref) $sql.=natural_search('f.ref', $search_ref); |
|
| 198 | +$sql .= " AND f.entity IN (".getEntity('invoice').") "; |
|
| 199 | +if (!empty($startdate)) $sql .= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
| 200 | +if (!empty($enddate)) $sql .= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
| 201 | +if ($search_ref) $sql .= natural_search('f.ref', $search_ref); |
|
| 202 | 202 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
| 203 | 203 | $sql .= $db->order($sortfield, $sortorder); |
| 204 | 204 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -$sql .= $db->plimit($limit+1, $offset); |
|
| 218 | +$sql .= $db->plimit($limit + 1, $offset); |
|
| 219 | 219 | |
| 220 | 220 | $result = $db->query($sql); |
| 221 | 221 | if ($result) { |
@@ -225,19 +225,19 @@ discard block |
||
| 225 | 225 | print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); |
| 226 | 226 | |
| 227 | 227 | if ($conf->global->MARGIN_TYPE == "1") |
| 228 | - $labelcostprice='BuyingPrice'; |
|
| 228 | + $labelcostprice = 'BuyingPrice'; |
|
| 229 | 229 | else // value is 'costprice' or 'pmp' |
| 230 | - $labelcostprice='CostPrice'; |
|
| 230 | + $labelcostprice = 'CostPrice'; |
|
| 231 | 231 | |
| 232 | - $moreforfilter=''; |
|
| 232 | + $moreforfilter = ''; |
|
| 233 | 233 | |
| 234 | - $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; |
|
| 234 | + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; |
|
| 235 | 235 | //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields |
| 236 | 236 | //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); |
| 237 | - $selectedfields=''; |
|
| 237 | + $selectedfields = ''; |
|
| 238 | 238 | |
| 239 | 239 | print '<div class="div-table-responsive">'; |
| 240 | - print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; |
|
| 240 | + print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n"; |
|
| 241 | 241 | |
| 242 | 242 | print '<tr class="liste_titre liste_titre_search">'; |
| 243 | 243 | print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>'; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | print '<td></td>'; |
| 248 | 248 | print '<td></td>'; |
| 249 | 249 | print '<td class="liste_titre" align="middle">'; |
| 250 | - $searchpitco=$form->showFilterButtons(); |
|
| 250 | + $searchpitco = $form->showFilterButtons(); |
|
| 251 | 251 | print $searchpitco; |
| 252 | 252 | print '</td>'; |
| 253 | 253 | print "</tr>\n"; |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
| 260 | 260 | print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder); |
| 261 | 261 | print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
| 262 | - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch '); |
|
| 262 | + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); |
|
| 263 | 263 | print "</tr>\n"; |
| 264 | 264 | |
| 265 | - $i=0; |
|
| 265 | + $i = 0; |
|
| 266 | 266 | while ($i < min($num, $limit)) |
| 267 | 267 | { |
| 268 | 268 | $objp = $db->fetch_object($result); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | print '</td>'; |
| 279 | 279 | print '<td>'; |
| 280 | - if (! empty($objp->fk_product)) { |
|
| 280 | + if (!empty($objp->fk_product)) { |
|
| 281 | 281 | $result_inner = $productstatic->fetch($objp->fk_product); |
| 282 | 282 | if ($result_inner < 0) { |
| 283 | 283 | setEventMessages($productstatic->error, null, 'errors'); |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | print price($objp->subprice); |
| 295 | 295 | print '</td>'; |
| 296 | 296 | print '<td align="right">'; |
| 297 | - print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">'; |
|
| 297 | + print '<input type="text" name="buyingprice_'.$objp->invoicedetid.'" id="buyingprice_'.$objp->invoicedetid.'" size="6" value="'.price($objp->buy_price_ht).'" class="right flat">'; |
|
| 298 | 298 | print '</td>'; |
| 299 | 299 | print '<td align="right">'; |
| 300 | 300 | print $objp->qty; |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | print "</tr>\n"; |
| 308 | 308 | |
| 309 | - $i ++; |
|
| 309 | + $i++; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | print "</table>"; |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | |
| 320 | -print '<div class="center">' . "\n"; |
|
| 321 | -print '<input type="submit" class="button" name="button_updatemagins" id="button_updatemagins" value="' . $langs->trans("Update") . '">'; |
|
| 320 | +print '<div class="center">'."\n"; |
|
| 321 | +print '<input type="submit" class="button" name="button_updatemagins" id="button_updatemagins" value="'.$langs->trans("Update").'">'; |
|
| 322 | 322 | print '</div>'; |
| 323 | 323 | |
| 324 | 324 | print '</form>'; |
@@ -29,29 +29,29 @@ |
||
| 29 | 29 | |
| 30 | 30 | if ($action == 'update' && is_array($arrayofparameters)) |
| 31 | 31 | { |
| 32 | - $db->begin(); |
|
| 32 | + $db->begin(); |
|
| 33 | 33 | |
| 34 | - $ok=true; |
|
| 35 | - foreach($arrayofparameters as $key => $val) |
|
| 36 | - { |
|
| 37 | - $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity); |
|
| 38 | - if ($result < 0) |
|
| 39 | - { |
|
| 40 | - $ok=false; |
|
| 41 | - break; |
|
| 42 | - } |
|
| 43 | - } |
|
| 34 | + $ok=true; |
|
| 35 | + foreach($arrayofparameters as $key => $val) |
|
| 36 | + { |
|
| 37 | + $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity); |
|
| 38 | + if ($result < 0) |
|
| 39 | + { |
|
| 40 | + $ok=false; |
|
| 41 | + break; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if (! $error) |
|
| 46 | - { |
|
| 47 | - $db->commit(); |
|
| 48 | - if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 49 | - } |
|
| 50 | - else |
|
| 51 | - { |
|
| 52 | - $db->rollback(); |
|
| 53 | - if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 54 | - } |
|
| 45 | + if (! $error) |
|
| 46 | + { |
|
| 47 | + $db->commit(); |
|
| 48 | + if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 49 | + } |
|
| 50 | + else |
|
| 51 | + { |
|
| 52 | + $db->rollback(); |
|
| 53 | + if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) |
@@ -31,18 +31,18 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | $db->begin(); |
| 33 | 33 | |
| 34 | - $ok=true; |
|
| 35 | - foreach($arrayofparameters as $key => $val) |
|
| 34 | + $ok = true; |
|
| 35 | + foreach ($arrayofparameters as $key => $val) |
|
| 36 | 36 | { |
| 37 | - $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity); |
|
| 37 | + $result = dolibarr_set_const($db, $key, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity); |
|
| 38 | 38 | if ($result < 0) |
| 39 | 39 | { |
| 40 | - $ok=false; |
|
| 40 | + $ok = false; |
|
| 41 | 41 | break; |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if (! $error) |
|
| 45 | + if (!$error) |
|
| 46 | 46 | { |
| 47 | 47 | $db->commit(); |
| 48 | 48 | if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
@@ -62,38 +62,38 @@ discard block |
||
| 62 | 62 | // Process common param fields |
| 63 | 63 | if (is_array($_POST)) |
| 64 | 64 | { |
| 65 | - foreach($_POST as $key => $val) |
|
| 65 | + foreach ($_POST as $key => $val) |
|
| 66 | 66 | { |
| 67 | 67 | if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... |
| 68 | 68 | { |
| 69 | - $param=GETPOST("param".$reg[1],'alpha'); |
|
| 70 | - $value=GETPOST("value".$reg[1],'alpha'); |
|
| 69 | + $param = GETPOST("param".$reg[1], 'alpha'); |
|
| 70 | + $value = GETPOST("value".$reg[1], 'alpha'); |
|
| 71 | 71 | if ($param) |
| 72 | 72 | { |
| 73 | - $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); |
|
| 74 | - if (! $res > 0) $error++; |
|
| 73 | + $res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity); |
|
| 74 | + if (!$res > 0) $error++; |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Process upload fields |
| 81 | - if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09')) |
|
| 81 | + if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09')) |
|
| 82 | 82 | { |
| 83 | 83 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 84 | - $keyforuploaddir=GETPOST('keyforuploaddir','aZ09'); |
|
| 85 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir))); |
|
| 86 | - foreach($listofdir as $key=>$tmpdir) |
|
| 84 | + $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09'); |
|
| 85 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir))); |
|
| 86 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 87 | 87 | { |
| 88 | - $tmpdir=trim($tmpdir); |
|
| 89 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 90 | - if (! $tmpdir) { |
|
| 88 | + $tmpdir = trim($tmpdir); |
|
| 89 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 90 | + if (!$tmpdir) { |
|
| 91 | 91 | unset($listofdir[$key]); continue; |
| 92 | 92 | } |
| 93 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 93 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 94 | 94 | else |
| 95 | 95 | { |
| 96 | - $upload_dir=$tmpdir; |
|
| 96 | + $upload_dir = $tmpdir; |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | if ($upload_dir) |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if (! $error) |
|
| 106 | + if (!$error) |
|
| 107 | 107 | { |
| 108 | 108 | $db->commit(); |
| 109 | 109 | if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
@@ -45,12 +45,15 @@ discard block |
||
| 45 | 45 | if (! $error) |
| 46 | 46 | { |
| 47 | 47 | $db->commit(); |
| 48 | - if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 49 | - } |
|
| 50 | - else |
|
| 48 | + if (empty($nomessageinupdate)) { |
|
| 49 | + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 50 | + } |
|
| 51 | + } else |
|
| 51 | 52 | { |
| 52 | 53 | $db->rollback(); |
| 53 | - if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 54 | + if (empty($nomessageinupdate)) { |
|
| 55 | + setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 56 | + } |
|
| 54 | 57 | } |
| 55 | 58 | } |
| 56 | 59 | |
@@ -64,14 +67,18 @@ discard block |
||
| 64 | 67 | { |
| 65 | 68 | foreach($_POST as $key => $val) |
| 66 | 69 | { |
| 67 | - if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... |
|
| 70 | + if (preg_match('/^param(\d*)$/', $key, $reg)) { |
|
| 71 | + // Works for POST['param'], POST['param1'], POST['param2'], ... |
|
| 68 | 72 | { |
| 69 | 73 | $param=GETPOST("param".$reg[1],'alpha'); |
| 74 | + } |
|
| 70 | 75 | $value=GETPOST("value".$reg[1],'alpha'); |
| 71 | 76 | if ($param) |
| 72 | 77 | { |
| 73 | 78 | $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); |
| 74 | - if (! $res > 0) $error++; |
|
| 79 | + if (! $res > 0) { |
|
| 80 | + $error++; |
|
| 81 | + } |
|
| 75 | 82 | } |
| 76 | 83 | } |
| 77 | 84 | } |
@@ -90,8 +97,9 @@ discard block |
||
| 90 | 97 | if (! $tmpdir) { |
| 91 | 98 | unset($listofdir[$key]); continue; |
| 92 | 99 | } |
| 93 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 94 | - else |
|
| 100 | + if (! is_dir($tmpdir)) { |
|
| 101 | + $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 102 | + } else |
|
| 95 | 103 | { |
| 96 | 104 | $upload_dir=$tmpdir; |
| 97 | 105 | } |
@@ -99,19 +107,24 @@ discard block |
||
| 99 | 107 | if ($upload_dir) |
| 100 | 108 | { |
| 101 | 109 | $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', ''); |
| 102 | - if ($result <= 0) $error++; |
|
| 110 | + if ($result <= 0) { |
|
| 111 | + $error++; |
|
| 112 | + } |
|
| 103 | 113 | } |
| 104 | 114 | } |
| 105 | 115 | |
| 106 | 116 | if (! $error) |
| 107 | 117 | { |
| 108 | 118 | $db->commit(); |
| 109 | - if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 110 | - } |
|
| 111 | - else |
|
| 119 | + if (empty($nomessageinsetmoduleoptions)) { |
|
| 120 | + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 121 | + } |
|
| 122 | + } else |
|
| 112 | 123 | { |
| 113 | 124 | $db->rollback(); |
| 114 | - if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 125 | + if (empty($nomessageinsetmoduleoptions)) { |
|
| 126 | + setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 127 | + } |
|
| 115 | 128 | } |
| 116 | 129 | } |
| 117 | 130 | |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | class InfoBox |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * Name of positions 0=Home, 1=... |
|
| 32 | - * |
|
| 33 | - * @return string[] Array with list of zones |
|
| 34 | - */ |
|
| 35 | - static function getListOfPagesForBoxes() |
|
| 36 | - { |
|
| 37 | - return array(0=>'Home'); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Name of positions 0=Home, 1=... |
|
| 32 | + * |
|
| 33 | + * @return string[] Array with list of zones |
|
| 34 | + */ |
|
| 35 | + static function getListOfPagesForBoxes() |
|
| 36 | + { |
|
| 37 | + return array(0=>'Home'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Return array of boxes qualified for area and user |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | $sql.= " ORDER BY b.box_order"; |
| 69 | 69 | } |
| 70 | 70 | else // available |
| 71 | - { |
|
| 71 | + { |
|
| 72 | 72 | $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms"; |
| 73 | 73 | $sql.= " FROM ".MAIN_DB_PREFIX."boxes_def as d"; |
| 74 | - $sql.= " WHERE d.entity IN (0,".$conf->entity.")"; |
|
| 74 | + $sql.= " WHERE d.entity IN (0,".$conf->entity.")"; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | dol_syslog(get_class()."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user)?$user->id:'')."", LOG_DEBUG); |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | $boxname=preg_replace('/\.php$/i','',$obj->file); |
| 99 | 99 | $relsourcefile = "/core/boxes/".$boxname.".php"; |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>'; |
|
| 102 | + //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>'; |
|
| 103 | 103 | |
| 104 | - // TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then |
|
| 104 | + // TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then |
|
| 105 | 105 | // the "enabled" condition for modules forbidden for external users and the depends condition can be done. |
| 106 | 106 | // Goal is to avoid making a "new" done for each boxes returned by select. |
| 107 | 107 | dol_include_once($relsourcefile); |
| 108 | 108 | if (class_exists($boxname)) |
| 109 | 109 | { |
| 110 | - $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. |
|
| 110 | + $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. |
|
| 111 | 111 | //$box=new stdClass(); |
| 112 | 112 | |
| 113 | 113 | // box properties |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | $box->box_order = (empty($obj->box_order) ? '' : $obj->box_order); |
| 118 | 118 | $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user); |
| 119 | 119 | $box->sourcefile= $relsourcefile; |
| 120 | - $box->class = $boxname; |
|
| 120 | + $box->class = $boxname; |
|
| 121 | 121 | |
| 122 | - if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database |
|
| 122 | + if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database |
|
| 123 | 123 | { |
| 124 | 124 | if (is_numeric($box->box_order)) |
| 125 | 125 | { |
@@ -138,19 +138,19 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | foreach($box->depends as $moduleelem) |
| 140 | 140 | { |
| 141 | - $arrayelem=explode('|',$moduleelem); |
|
| 142 | - $tmpenabled=0; // $tmpenabled is used for the '|' test (OR) |
|
| 143 | - foreach($arrayelem as $module) |
|
| 144 | - { |
|
| 145 | - $tmpmodule=preg_replace('/@[^@]+/','',$module); |
|
| 146 | - if (! empty($conf->$tmpmodule->enabled)) $tmpenabled=1; |
|
| 147 | - //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>'; |
|
| 148 | - } |
|
| 149 | - if (empty($tmpenabled)) // We found at least one module required that is disabled |
|
| 150 | - { |
|
| 151 | - $enabled=0; |
|
| 152 | - break; |
|
| 153 | - } |
|
| 141 | + $arrayelem=explode('|',$moduleelem); |
|
| 142 | + $tmpenabled=0; // $tmpenabled is used for the '|' test (OR) |
|
| 143 | + foreach($arrayelem as $module) |
|
| 144 | + { |
|
| 145 | + $tmpmodule=preg_replace('/@[^@]+/','',$module); |
|
| 146 | + if (! empty($conf->$tmpmodule->enabled)) $tmpenabled=1; |
|
| 147 | + //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>'; |
|
| 148 | + } |
|
| 149 | + if (empty($tmpenabled)) // We found at least one module required that is disabled |
|
| 150 | + { |
|
| 151 | + $enabled=0; |
|
| 152 | + break; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | //print '=>'.$boxname.'-enabled='.$enabled.'<br>'; |
@@ -160,16 +160,16 @@ discard block |
||
| 160 | 160 | else unset($box); |
| 161 | 161 | } |
| 162 | 162 | else |
| 163 | - { |
|
| 164 | - dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING); |
|
| 165 | - } |
|
| 163 | + { |
|
| 164 | + dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING); |
|
| 165 | + } |
|
| 166 | 166 | } |
| 167 | 167 | $j++; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | - { |
|
| 172 | - dol_syslog($db->lasterror(),LOG_ERR); |
|
| 171 | + { |
|
| 172 | + dol_syslog($db->lasterror(),LOG_ERR); |
|
| 173 | 173 | return array('error'=>$db->lasterror()); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -48,33 +48,33 @@ discard block |
||
| 48 | 48 | * @param int $includehidden Include also hidden boxes |
| 49 | 49 | * @return array Array of boxes |
| 50 | 50 | */ |
| 51 | - static function listBoxes($db, $mode, $zone, $user=null, $excludelist=array(), $includehidden=1) |
|
| 51 | + static function listBoxes($db, $mode, $zone, $user = null, $excludelist = array(), $includehidden = 1) |
|
| 52 | 52 | { |
| 53 | 53 | global $conf; |
| 54 | 54 | |
| 55 | - $boxes=array(); |
|
| 55 | + $boxes = array(); |
|
| 56 | 56 | |
| 57 | - $confuserzone='MAIN_BOXES_'.$zone; |
|
| 57 | + $confuserzone = 'MAIN_BOXES_'.$zone; |
|
| 58 | 58 | if ($mode == 'activated') // activated |
| 59 | 59 | { |
| 60 | 60 | $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,"; |
| 61 | - $sql.= " d.rowid as box_id, d.file, d.note, d.tms"; |
|
| 62 | - $sql.= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; |
|
| 63 | - $sql.= " WHERE b.box_id = d.rowid"; |
|
| 64 | - $sql.= " AND b.entity IN (0,".$conf->entity.")"; |
|
| 65 | - if ($zone >= 0) $sql.= " AND b.position = ".$zone; |
|
| 66 | - if (is_object($user)) $sql.= " AND b.fk_user IN (0,".$user->id.")"; |
|
| 67 | - else $sql.= " AND b.fk_user = 0"; |
|
| 68 | - $sql.= " ORDER BY b.box_order"; |
|
| 61 | + $sql .= " d.rowid as box_id, d.file, d.note, d.tms"; |
|
| 62 | + $sql .= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; |
|
| 63 | + $sql .= " WHERE b.box_id = d.rowid"; |
|
| 64 | + $sql .= " AND b.entity IN (0,".$conf->entity.")"; |
|
| 65 | + if ($zone >= 0) $sql .= " AND b.position = ".$zone; |
|
| 66 | + if (is_object($user)) $sql .= " AND b.fk_user IN (0,".$user->id.")"; |
|
| 67 | + else $sql .= " AND b.fk_user = 0"; |
|
| 68 | + $sql .= " ORDER BY b.box_order"; |
|
| 69 | 69 | } |
| 70 | 70 | else // available |
| 71 | 71 | { |
| 72 | 72 | $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms"; |
| 73 | - $sql.= " FROM ".MAIN_DB_PREFIX."boxes_def as d"; |
|
| 74 | - $sql.= " WHERE d.entity IN (0,".$conf->entity.")"; |
|
| 73 | + $sql .= " FROM ".MAIN_DB_PREFIX."boxes_def as d"; |
|
| 74 | + $sql .= " WHERE d.entity IN (0,".$conf->entity.")"; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - dol_syslog(get_class()."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user)?$user->id:'')."", LOG_DEBUG); |
|
| 77 | + dol_syslog(get_class()."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user) ? $user->id : '')."", LOG_DEBUG); |
|
| 78 | 78 | $resql = $db->query($sql); |
| 79 | 79 | if ($resql) |
| 80 | 80 | { |
@@ -84,18 +84,18 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | $obj = $db->fetch_object($resql); |
| 86 | 86 | |
| 87 | - if (! in_array($obj->box_id, $excludelist)) |
|
| 87 | + if (!in_array($obj->box_id, $excludelist)) |
|
| 88 | 88 | { |
| 89 | 89 | |
| 90 | - if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) |
|
| 90 | + if (preg_match('/^([^@]+)@([^@]+)$/i', $obj->file, $regs)) |
|
| 91 | 91 | { |
| 92 | - $boxname = preg_replace('/\.php$/i','',$regs[1]); |
|
| 92 | + $boxname = preg_replace('/\.php$/i', '', $regs[1]); |
|
| 93 | 93 | $module = $regs[2]; |
| 94 | 94 | $relsourcefile = "/".$module."/core/boxes/".$boxname.".php"; |
| 95 | 95 | } |
| 96 | 96 | else |
| 97 | 97 | { |
| 98 | - $boxname=preg_replace('/\.php$/i','',$obj->file); |
|
| 98 | + $boxname = preg_replace('/\.php$/i', '', $obj->file); |
|
| 99 | 99 | $relsourcefile = "/core/boxes/".$boxname.".php"; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -107,48 +107,48 @@ discard block |
||
| 107 | 107 | dol_include_once($relsourcefile); |
| 108 | 108 | if (class_exists($boxname)) |
| 109 | 109 | { |
| 110 | - $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. |
|
| 110 | + $box = new $boxname($db, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. |
|
| 111 | 111 | //$box=new stdClass(); |
| 112 | 112 | |
| 113 | 113 | // box properties |
| 114 | - $box->rowid = (empty($obj->rowid) ? '' : $obj->rowid); |
|
| 115 | - $box->id = (empty($obj->box_id) ? '' : $obj->box_id); |
|
| 116 | - $box->position = ($obj->position == '' ? '' : $obj->position); // '0' must staty '0' |
|
| 114 | + $box->rowid = (empty($obj->rowid) ? '' : $obj->rowid); |
|
| 115 | + $box->id = (empty($obj->box_id) ? '' : $obj->box_id); |
|
| 116 | + $box->position = ($obj->position == '' ? '' : $obj->position); // '0' must staty '0' |
|
| 117 | 117 | $box->box_order = (empty($obj->box_order) ? '' : $obj->box_order); |
| 118 | - $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user); |
|
| 119 | - $box->sourcefile= $relsourcefile; |
|
| 120 | - $box->class = $boxname; |
|
| 118 | + $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user); |
|
| 119 | + $box->sourcefile = $relsourcefile; |
|
| 120 | + $box->class = $boxname; |
|
| 121 | 121 | |
| 122 | - if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database |
|
| 122 | + if ($mode == 'activated' && !is_object($user)) // List of activated box was not yet personalized into database |
|
| 123 | 123 | { |
| 124 | 124 | if (is_numeric($box->box_order)) |
| 125 | 125 | { |
| 126 | - if ($box->box_order % 2 == 1) $box->box_order='A'.$box->box_order; |
|
| 127 | - elseif ($box->box_order % 2 == 0) $box->box_order='B'.$box->box_order; |
|
| 126 | + if ($box->box_order % 2 == 1) $box->box_order = 'A'.$box->box_order; |
|
| 127 | + elseif ($box->box_order % 2 == 0) $box->box_order = 'B'.$box->box_order; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | // box_def properties |
| 131 | - $box->box_id = (empty($obj->box_id) ? '' : $obj->box_id); |
|
| 132 | - $box->note = (empty($obj->note) ? '' : $obj->note); |
|
| 131 | + $box->box_id = (empty($obj->box_id) ? '' : $obj->box_id); |
|
| 132 | + $box->note = (empty($obj->note) ? '' : $obj->note); |
|
| 133 | 133 | |
| 134 | 134 | // Filter on box->enabled (used for example by box_comptes) |
| 135 | 135 | // Filter also on box->depends. Example: array("product|service") or array("contrat", "service") |
| 136 | - $enabled=$box->enabled; |
|
| 136 | + $enabled = $box->enabled; |
|
| 137 | 137 | if (isset($box->depends) && count($box->depends) > 0) |
| 138 | 138 | { |
| 139 | - foreach($box->depends as $moduleelem) |
|
| 139 | + foreach ($box->depends as $moduleelem) |
|
| 140 | 140 | { |
| 141 | - $arrayelem=explode('|',$moduleelem); |
|
| 142 | - $tmpenabled=0; // $tmpenabled is used for the '|' test (OR) |
|
| 143 | - foreach($arrayelem as $module) |
|
| 141 | + $arrayelem = explode('|', $moduleelem); |
|
| 142 | + $tmpenabled = 0; // $tmpenabled is used for the '|' test (OR) |
|
| 143 | + foreach ($arrayelem as $module) |
|
| 144 | 144 | { |
| 145 | - $tmpmodule=preg_replace('/@[^@]+/','',$module); |
|
| 146 | - if (! empty($conf->$tmpmodule->enabled)) $tmpenabled=1; |
|
| 145 | + $tmpmodule = preg_replace('/@[^@]+/', '', $module); |
|
| 146 | + if (!empty($conf->$tmpmodule->enabled)) $tmpenabled = 1; |
|
| 147 | 147 | //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>'; |
| 148 | 148 | } |
| 149 | 149 | if (empty($tmpenabled)) // We found at least one module required that is disabled |
| 150 | 150 | { |
| 151 | - $enabled=0; |
|
| 151 | + $enabled = 0; |
|
| 152 | 152 | break; |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | //print '=>'.$boxname.'-enabled='.$enabled.'<br>'; |
| 157 | 157 | |
| 158 | 158 | //print 'xx module='.$module.' enabled='.$enabled; |
| 159 | - if ($enabled && ($includehidden || empty($box->hidden))) $boxes[]=$box; |
|
| 159 | + if ($enabled && ($includehidden || empty($box->hidden))) $boxes[] = $box; |
|
| 160 | 160 | else unset($box); |
| 161 | 161 | } |
| 162 | 162 | else |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | 171 | { |
| 172 | - dol_syslog($db->lasterror(),LOG_ERR); |
|
| 172 | + dol_syslog($db->lasterror(), LOG_ERR); |
|
| 173 | 173 | return array('error'=>$db->lasterror()); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -186,70 +186,70 @@ discard block |
||
| 186 | 186 | * @param int $userid Id of user |
| 187 | 187 | * @return int <0 if KO, 0=Nothing done, > 0 if OK |
| 188 | 188 | */ |
| 189 | - static function saveboxorder($db, $zone,$boxorder,$userid=0) |
|
| 189 | + static function saveboxorder($db, $zone, $boxorder, $userid = 0) |
|
| 190 | 190 | { |
| 191 | 191 | global $conf; |
| 192 | 192 | |
| 193 | - $error=0; |
|
| 193 | + $error = 0; |
|
| 194 | 194 | |
| 195 | 195 | require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
| 196 | 196 | |
| 197 | 197 | dol_syslog(get_class()."::saveboxorder zone=".$zone." userid=".$userid); |
| 198 | 198 | |
| 199 | - if (! $userid || $userid == 0) return 0; |
|
| 199 | + if (!$userid || $userid == 0) return 0; |
|
| 200 | 200 | |
| 201 | 201 | $user = new User($db); |
| 202 | - $user->id=$userid; |
|
| 202 | + $user->id = $userid; |
|
| 203 | 203 | |
| 204 | 204 | $db->begin(); |
| 205 | 205 | |
| 206 | 206 | // Save parameters to say user has a dedicated setup |
| 207 | - $tab=array(); |
|
| 208 | - $confuserzone='MAIN_BOXES_'.$zone; |
|
| 209 | - $tab[$confuserzone]=1; |
|
| 207 | + $tab = array(); |
|
| 208 | + $confuserzone = 'MAIN_BOXES_'.$zone; |
|
| 209 | + $tab[$confuserzone] = 1; |
|
| 210 | 210 | if (dol_set_user_param($db, $conf, $user, $tab) < 0) |
| 211 | 211 | { |
| 212 | - $error=$db->lasterror(); |
|
| 212 | + $error = $db->lasterror(); |
|
| 213 | 213 | $db->rollback(); |
| 214 | 214 | return -3; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // Delete all lines |
| 218 | 218 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes"; |
| 219 | - $sql.= " WHERE entity = ".$conf->entity; |
|
| 220 | - $sql.= " AND fk_user = ".$userid; |
|
| 221 | - $sql.= " AND position = ".$zone; |
|
| 219 | + $sql .= " WHERE entity = ".$conf->entity; |
|
| 220 | + $sql .= " AND fk_user = ".$userid; |
|
| 221 | + $sql .= " AND position = ".$zone; |
|
| 222 | 222 | |
| 223 | 223 | dol_syslog(get_class()."::saveboxorder", LOG_DEBUG); |
| 224 | 224 | $result = $db->query($sql); |
| 225 | 225 | if ($result) |
| 226 | 226 | { |
| 227 | - $colonnes=explode('-',$boxorder); |
|
| 227 | + $colonnes = explode('-', $boxorder); |
|
| 228 | 228 | foreach ($colonnes as $collist) |
| 229 | 229 | { |
| 230 | - $part=explode(':',$collist); |
|
| 231 | - $colonne=$part[0]; |
|
| 232 | - $list=$part[1]; |
|
| 230 | + $part = explode(':', $collist); |
|
| 231 | + $colonne = $part[0]; |
|
| 232 | + $list = $part[1]; |
|
| 233 | 233 | dol_syslog(get_class()."::saveboxorder column=".$colonne.' list='.$list); |
| 234 | 234 | |
| 235 | - $i=0; |
|
| 236 | - $listarray=explode(',',$list); |
|
| 235 | + $i = 0; |
|
| 236 | + $listarray = explode(',', $list); |
|
| 237 | 237 | foreach ($listarray as $id) |
| 238 | 238 | { |
| 239 | 239 | if (is_numeric($id)) |
| 240 | 240 | { |
| 241 | 241 | //dol_syslog("aaaaa".count($listarray)); |
| 242 | 242 | $i++; |
| 243 | - $ii=sprintf('%02d',$i); |
|
| 243 | + $ii = sprintf('%02d', $i); |
|
| 244 | 244 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes"; |
| 245 | - $sql.= "(box_id, position, box_order, fk_user, entity)"; |
|
| 246 | - $sql.= " values ("; |
|
| 247 | - $sql.= " ".$id.","; |
|
| 248 | - $sql.= " ".$zone.","; |
|
| 249 | - $sql.= " '".$colonne.$ii."',"; |
|
| 250 | - $sql.= " ".$userid.","; |
|
| 251 | - $sql.= " ".$conf->entity; |
|
| 252 | - $sql.= ")"; |
|
| 245 | + $sql .= "(box_id, position, box_order, fk_user, entity)"; |
|
| 246 | + $sql .= " values ("; |
|
| 247 | + $sql .= " ".$id.","; |
|
| 248 | + $sql .= " ".$zone.","; |
|
| 249 | + $sql .= " '".$colonne.$ii."',"; |
|
| 250 | + $sql .= " ".$userid.","; |
|
| 251 | + $sql .= " ".$conf->entity; |
|
| 252 | + $sql .= ")"; |
|
| 253 | 253 | |
| 254 | 254 | dol_syslog(get_class()."::saveboxorder", LOG_DEBUG); |
| 255 | 255 | $result = $db->query($sql); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | if ($error) |
| 265 | 265 | { |
| 266 | - $error=$db->error(); |
|
| 266 | + $error = $db->error(); |
|
| 267 | 267 | $db->rollback(); |
| 268 | 268 | return -2; |
| 269 | 269 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | else |
| 277 | 277 | { |
| 278 | - $error=$db->lasterror(); |
|
| 278 | + $error = $db->lasterror(); |
|
| 279 | 279 | $db->rollback(); |
| 280 | 280 | dol_syslog(get_class()."::saveboxorder ".$error); |
| 281 | 281 | return -1; |
@@ -55,19 +55,25 @@ discard block |
||
| 55 | 55 | $boxes=array(); |
| 56 | 56 | |
| 57 | 57 | $confuserzone='MAIN_BOXES_'.$zone; |
| 58 | - if ($mode == 'activated') // activated |
|
| 58 | + if ($mode == 'activated') { |
|
| 59 | + // activated |
|
| 59 | 60 | { |
| 60 | 61 | $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,"; |
| 62 | + } |
|
| 61 | 63 | $sql.= " d.rowid as box_id, d.file, d.note, d.tms"; |
| 62 | 64 | $sql.= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; |
| 63 | 65 | $sql.= " WHERE b.box_id = d.rowid"; |
| 64 | 66 | $sql.= " AND b.entity IN (0,".$conf->entity.")"; |
| 65 | - if ($zone >= 0) $sql.= " AND b.position = ".$zone; |
|
| 66 | - if (is_object($user)) $sql.= " AND b.fk_user IN (0,".$user->id.")"; |
|
| 67 | - else $sql.= " AND b.fk_user = 0"; |
|
| 67 | + if ($zone >= 0) { |
|
| 68 | + $sql.= " AND b.position = ".$zone; |
|
| 69 | + } |
|
| 70 | + if (is_object($user)) { |
|
| 71 | + $sql.= " AND b.fk_user IN (0,".$user->id.")"; |
|
| 72 | + } else { |
|
| 73 | + $sql.= " AND b.fk_user = 0"; |
|
| 74 | + } |
|
| 68 | 75 | $sql.= " ORDER BY b.box_order"; |
| 69 | - } |
|
| 70 | - else // available |
|
| 76 | + } else // available |
|
| 71 | 77 | { |
| 72 | 78 | $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms"; |
| 73 | 79 | $sql.= " FROM ".MAIN_DB_PREFIX."boxes_def as d"; |
@@ -92,8 +98,7 @@ discard block |
||
| 92 | 98 | $boxname = preg_replace('/\.php$/i','',$regs[1]); |
| 93 | 99 | $module = $regs[2]; |
| 94 | 100 | $relsourcefile = "/".$module."/core/boxes/".$boxname.".php"; |
| 95 | - } |
|
| 96 | - else |
|
| 101 | + } else |
|
| 97 | 102 | { |
| 98 | 103 | $boxname=preg_replace('/\.php$/i','',$obj->file); |
| 99 | 104 | $relsourcefile = "/core/boxes/".$boxname.".php"; |
@@ -119,12 +124,15 @@ discard block |
||
| 119 | 124 | $box->sourcefile= $relsourcefile; |
| 120 | 125 | $box->class = $boxname; |
| 121 | 126 | |
| 122 | - if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database |
|
| 127 | + if ($mode == 'activated' && ! is_object($user)) { |
|
| 128 | + // List of activated box was not yet personalized into database |
|
| 123 | 129 | { |
| 124 | 130 | if (is_numeric($box->box_order)) |
| 125 | 131 | { |
| 126 | 132 | if ($box->box_order % 2 == 1) $box->box_order='A'.$box->box_order; |
| 127 | - elseif ($box->box_order % 2 == 0) $box->box_order='B'.$box->box_order; |
|
| 133 | + } elseif ($box->box_order % 2 == 0) { |
|
| 134 | + $box->box_order='B'.$box->box_order; |
|
| 135 | + } |
|
| 128 | 136 | } |
| 129 | 137 | } |
| 130 | 138 | // box_def properties |
@@ -143,12 +151,16 @@ discard block |
||
| 143 | 151 | foreach($arrayelem as $module) |
| 144 | 152 | { |
| 145 | 153 | $tmpmodule=preg_replace('/@[^@]+/','',$module); |
| 146 | - if (! empty($conf->$tmpmodule->enabled)) $tmpenabled=1; |
|
| 154 | + if (! empty($conf->$tmpmodule->enabled)) { |
|
| 155 | + $tmpenabled=1; |
|
| 156 | + } |
|
| 147 | 157 | //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>'; |
| 148 | 158 | } |
| 149 | - if (empty($tmpenabled)) // We found at least one module required that is disabled |
|
| 159 | + if (empty($tmpenabled)) { |
|
| 160 | + // We found at least one module required that is disabled |
|
| 150 | 161 | { |
| 151 | 162 | $enabled=0; |
| 163 | + } |
|
| 152 | 164 | break; |
| 153 | 165 | } |
| 154 | 166 | } |
@@ -156,18 +168,19 @@ discard block |
||
| 156 | 168 | //print '=>'.$boxname.'-enabled='.$enabled.'<br>'; |
| 157 | 169 | |
| 158 | 170 | //print 'xx module='.$module.' enabled='.$enabled; |
| 159 | - if ($enabled && ($includehidden || empty($box->hidden))) $boxes[]=$box; |
|
| 160 | - else unset($box); |
|
| 161 | - } |
|
| 162 | - else |
|
| 171 | + if ($enabled && ($includehidden || empty($box->hidden))) { |
|
| 172 | + $boxes[]=$box; |
|
| 173 | + } else { |
|
| 174 | + unset($box); |
|
| 175 | + } |
|
| 176 | + } else |
|
| 163 | 177 | { |
| 164 | 178 | dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING); |
| 165 | 179 | } |
| 166 | 180 | } |
| 167 | 181 | $j++; |
| 168 | 182 | } |
| 169 | - } |
|
| 170 | - else |
|
| 183 | + } else |
|
| 171 | 184 | { |
| 172 | 185 | dol_syslog($db->lasterror(),LOG_ERR); |
| 173 | 186 | return array('error'=>$db->lasterror()); |
@@ -196,7 +209,9 @@ discard block |
||
| 196 | 209 | |
| 197 | 210 | dol_syslog(get_class()."::saveboxorder zone=".$zone." userid=".$userid); |
| 198 | 211 | |
| 199 | - if (! $userid || $userid == 0) return 0; |
|
| 212 | + if (! $userid || $userid == 0) { |
|
| 213 | + return 0; |
|
| 214 | + } |
|
| 200 | 215 | |
| 201 | 216 | $user = new User($db); |
| 202 | 217 | $user->id=$userid; |
@@ -266,14 +281,12 @@ discard block |
||
| 266 | 281 | $error=$db->error(); |
| 267 | 282 | $db->rollback(); |
| 268 | 283 | return -2; |
| 269 | - } |
|
| 270 | - else |
|
| 284 | + } else |
|
| 271 | 285 | { |
| 272 | 286 | $db->commit(); |
| 273 | 287 | return 1; |
| 274 | 288 | } |
| 275 | - } |
|
| 276 | - else |
|
| 289 | + } else |
|
| 277 | 290 | { |
| 278 | 291 | $error=$db->lasterror(); |
| 279 | 292 | $db->rollback(); |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | public $db; |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * @var string Error code (or message) |
|
| 37 | - */ |
|
| 38 | - public $error=''; |
|
| 36 | + * @var string Error code (or message) |
|
| 37 | + */ |
|
| 38 | + public $error=''; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -50,99 +50,99 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 53 | - /** |
|
| 54 | - * Show a combo list with contracts qualified for a third party |
|
| 55 | - * |
|
| 56 | - * @param int $socid Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id) |
|
| 57 | - * @param int $selected Id intervention preselected |
|
| 58 | - * @param string $htmlname Nom de la zone html |
|
| 59 | - * @param int $maxlength Maximum length of label |
|
| 60 | - * @param int $showempty Show empty line |
|
| 61 | - * @return int Nbre of project if OK, <0 if KO |
|
| 62 | - */ |
|
| 63 | - function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
|
| 64 | - { |
|
| 53 | + /** |
|
| 54 | + * Show a combo list with contracts qualified for a third party |
|
| 55 | + * |
|
| 56 | + * @param int $socid Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id) |
|
| 57 | + * @param int $selected Id intervention preselected |
|
| 58 | + * @param string $htmlname Nom de la zone html |
|
| 59 | + * @param int $maxlength Maximum length of label |
|
| 60 | + * @param int $showempty Show empty line |
|
| 61 | + * @return int Nbre of project if OK, <0 if KO |
|
| 62 | + */ |
|
| 63 | + function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
|
| 64 | + { |
|
| 65 | 65 | // phpcs:enable |
| 66 | - global $db,$user,$conf,$langs; |
|
| 66 | + global $db,$user,$conf,$langs; |
|
| 67 | 67 | |
| 68 | - $out=''; |
|
| 68 | + $out=''; |
|
| 69 | 69 | |
| 70 | - $hideunselectables=false; |
|
| 70 | + $hideunselectables=false; |
|
| 71 | 71 | |
| 72 | - // Search all contacts |
|
| 73 | - $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut'; |
|
| 74 | - $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f'; |
|
| 75 | - $sql.= " WHERE f.entity = ".$conf->entity; |
|
| 76 | - if ($socid != '') |
|
| 77 | - { |
|
| 78 | - if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | - else $sql.= " AND f.fk_soc = ".$socid; |
|
| 80 | - } |
|
| 72 | + // Search all contacts |
|
| 73 | + $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut'; |
|
| 74 | + $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f'; |
|
| 75 | + $sql.= " WHERE f.entity = ".$conf->entity; |
|
| 76 | + if ($socid != '') |
|
| 77 | + { |
|
| 78 | + if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | + else $sql.= " AND f.fk_soc = ".$socid; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
|
| 83 | - $resql=$db->query($sql); |
|
| 84 | - if ($resql) |
|
| 85 | - { |
|
| 86 | - $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
| 87 | - if ($showempty) $out.='<option value="0"> </option>'; |
|
| 88 | - $num = $db->num_rows($resql); |
|
| 89 | - $i = 0; |
|
| 90 | - if ($num) |
|
| 91 | - { |
|
| 92 | - while ($i < $num) |
|
| 93 | - { |
|
| 94 | - $obj = $db->fetch_object($resql); |
|
| 95 | - // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
|
| 96 | - if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
| 97 | - { |
|
| 98 | - // Do nothing |
|
| 99 | - } |
|
| 100 | - else |
|
| 101 | - { |
|
| 102 | - $labeltoshow=dol_trunc($obj->ref,18); |
|
| 103 | - if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
|
| 104 | - { |
|
| 105 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 106 | - } |
|
| 107 | - else |
|
| 108 | - { |
|
| 109 | - $disabled=0; |
|
| 110 | - if (! $obj->fk_statut > 0) |
|
| 111 | - { |
|
| 112 | - $disabled=1; |
|
| 113 | - $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 114 | - } |
|
| 115 | - if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 116 | - { |
|
| 117 | - $disabled=1; |
|
| 118 | - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 119 | - } |
|
| 82 | + dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
|
| 83 | + $resql=$db->query($sql); |
|
| 84 | + if ($resql) |
|
| 85 | + { |
|
| 86 | + $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
| 87 | + if ($showempty) $out.='<option value="0"> </option>'; |
|
| 88 | + $num = $db->num_rows($resql); |
|
| 89 | + $i = 0; |
|
| 90 | + if ($num) |
|
| 91 | + { |
|
| 92 | + while ($i < $num) |
|
| 93 | + { |
|
| 94 | + $obj = $db->fetch_object($resql); |
|
| 95 | + // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
|
| 96 | + if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
| 97 | + { |
|
| 98 | + // Do nothing |
|
| 99 | + } |
|
| 100 | + else |
|
| 101 | + { |
|
| 102 | + $labeltoshow=dol_trunc($obj->ref,18); |
|
| 103 | + if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
|
| 104 | + { |
|
| 105 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 106 | + } |
|
| 107 | + else |
|
| 108 | + { |
|
| 109 | + $disabled=0; |
|
| 110 | + if (! $obj->fk_statut > 0) |
|
| 111 | + { |
|
| 112 | + $disabled=1; |
|
| 113 | + $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 114 | + } |
|
| 115 | + if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 116 | + { |
|
| 117 | + $disabled=1; |
|
| 118 | + $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - if ($hideunselectables && $disabled) |
|
| 122 | - { |
|
| 123 | - $resultat=''; |
|
| 124 | - } |
|
| 125 | - else |
|
| 126 | - { |
|
| 127 | - $resultat='<option value="'.$obj->rowid.'"'; |
|
| 128 | - if ($disabled) $resultat.=' disabled'; |
|
| 129 | - $resultat.='>'.$labeltoshow; |
|
| 130 | - $resultat.='</option>'; |
|
| 131 | - } |
|
| 132 | - $out.=$resultat; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - $i++; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - $out.='</select>'; |
|
| 139 | - $db->free($resql); |
|
| 140 | - return $out; |
|
| 141 | - } |
|
| 142 | - else |
|
| 143 | - { |
|
| 144 | - dol_print_error($db); |
|
| 145 | - return ''; |
|
| 146 | - } |
|
| 147 | - } |
|
| 121 | + if ($hideunselectables && $disabled) |
|
| 122 | + { |
|
| 123 | + $resultat=''; |
|
| 124 | + } |
|
| 125 | + else |
|
| 126 | + { |
|
| 127 | + $resultat='<option value="'.$obj->rowid.'"'; |
|
| 128 | + if ($disabled) $resultat.=' disabled'; |
|
| 129 | + $resultat.='>'.$labeltoshow; |
|
| 130 | + $resultat.='</option>'; |
|
| 131 | + } |
|
| 132 | + $out.=$resultat; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + $i++; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + $out.='</select>'; |
|
| 139 | + $db->free($resql); |
|
| 140 | + return $out; |
|
| 141 | + } |
|
| 142 | + else |
|
| 143 | + { |
|
| 144 | + dol_print_error($db); |
|
| 145 | + return ''; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * @var string Error code (or message) |
| 37 | 37 | */ |
| 38 | - public $error=''; |
|
| 38 | + public $error = ''; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -60,31 +60,31 @@ discard block |
||
| 60 | 60 | * @param int $showempty Show empty line |
| 61 | 61 | * @return int Nbre of project if OK, <0 if KO |
| 62 | 62 | */ |
| 63 | - function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
|
| 63 | + function select_interventions($socid = -1, $selected = '', $htmlname = 'interventionid', $maxlength = 16, $showempty = 1) |
|
| 64 | 64 | { |
| 65 | 65 | // phpcs:enable |
| 66 | - global $db,$user,$conf,$langs; |
|
| 66 | + global $db, $user, $conf, $langs; |
|
| 67 | 67 | |
| 68 | - $out=''; |
|
| 68 | + $out = ''; |
|
| 69 | 69 | |
| 70 | - $hideunselectables=false; |
|
| 70 | + $hideunselectables = false; |
|
| 71 | 71 | |
| 72 | 72 | // Search all contacts |
| 73 | 73 | $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut'; |
| 74 | - $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f'; |
|
| 75 | - $sql.= " WHERE f.entity = ".$conf->entity; |
|
| 74 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter as f'; |
|
| 75 | + $sql .= " WHERE f.entity = ".$conf->entity; |
|
| 76 | 76 | if ($socid != '') |
| 77 | 77 | { |
| 78 | - if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | - else $sql.= " AND f.fk_soc = ".$socid; |
|
| 78 | + if ($socid == '0') $sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | + else $sql .= " AND f.fk_soc = ".$socid; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
| 83 | - $resql=$db->query($sql); |
|
| 83 | + $resql = $db->query($sql); |
|
| 84 | 84 | if ($resql) |
| 85 | 85 | { |
| 86 | - $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
| 87 | - if ($showempty) $out.='<option value="0"> </option>'; |
|
| 86 | + $out .= '<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
| 87 | + if ($showempty) $out .= '<option value="0"> </option>'; |
|
| 88 | 88 | $num = $db->num_rows($resql); |
| 89 | 89 | $i = 0; |
| 90 | 90 | if ($num) |
@@ -93,49 +93,49 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $obj = $db->fetch_object($resql); |
| 95 | 95 | // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
| 96 | - if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
| 96 | + if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire) |
|
| 97 | 97 | { |
| 98 | 98 | // Do nothing |
| 99 | 99 | } |
| 100 | 100 | else |
| 101 | 101 | { |
| 102 | - $labeltoshow=dol_trunc($obj->ref,18); |
|
| 102 | + $labeltoshow = dol_trunc($obj->ref, 18); |
|
| 103 | 103 | if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
| 104 | 104 | { |
| 105 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 105 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 106 | 106 | } |
| 107 | 107 | else |
| 108 | 108 | { |
| 109 | - $disabled=0; |
|
| 110 | - if (! $obj->fk_statut > 0) |
|
| 109 | + $disabled = 0; |
|
| 110 | + if (!$obj->fk_statut > 0) |
|
| 111 | 111 | { |
| 112 | - $disabled=1; |
|
| 113 | - $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 112 | + $disabled = 1; |
|
| 113 | + $labeltoshow .= ' ('.$langs->trans("Draft").')'; |
|
| 114 | 114 | } |
| 115 | - if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 115 | + if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 116 | 116 | { |
| 117 | - $disabled=1; |
|
| 118 | - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 117 | + $disabled = 1; |
|
| 118 | + $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | if ($hideunselectables && $disabled) |
| 122 | 122 | { |
| 123 | - $resultat=''; |
|
| 123 | + $resultat = ''; |
|
| 124 | 124 | } |
| 125 | 125 | else |
| 126 | 126 | { |
| 127 | - $resultat='<option value="'.$obj->rowid.'"'; |
|
| 128 | - if ($disabled) $resultat.=' disabled'; |
|
| 129 | - $resultat.='>'.$labeltoshow; |
|
| 130 | - $resultat.='</option>'; |
|
| 127 | + $resultat = '<option value="'.$obj->rowid.'"'; |
|
| 128 | + if ($disabled) $resultat .= ' disabled'; |
|
| 129 | + $resultat .= '>'.$labeltoshow; |
|
| 130 | + $resultat .= '</option>'; |
|
| 131 | 131 | } |
| 132 | - $out.=$resultat; |
|
| 132 | + $out .= $resultat; |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | $i++; |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | - $out.='</select>'; |
|
| 138 | + $out .= '</select>'; |
|
| 139 | 139 | $db->free($resql); |
| 140 | 140 | return $out; |
| 141 | 141 | } |
@@ -75,8 +75,11 @@ discard block |
||
| 75 | 75 | $sql.= " WHERE f.entity = ".$conf->entity; |
| 76 | 76 | if ($socid != '') |
| 77 | 77 | { |
| 78 | - if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | - else $sql.= " AND f.fk_soc = ".$socid; |
|
| 78 | + if ($socid == '0') { |
|
| 79 | + $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 80 | + } else { |
|
| 81 | + $sql.= " AND f.fk_soc = ".$socid; |
|
| 82 | + } |
|
| 80 | 83 | } |
| 81 | 84 | |
| 82 | 85 | dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
@@ -84,7 +87,9 @@ discard block |
||
| 84 | 87 | if ($resql) |
| 85 | 88 | { |
| 86 | 89 | $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
| 87 | - if ($showempty) $out.='<option value="0"> </option>'; |
|
| 90 | + if ($showempty) { |
|
| 91 | + $out.='<option value="0"> </option>'; |
|
| 92 | + } |
|
| 88 | 93 | $num = $db->num_rows($resql); |
| 89 | 94 | $i = 0; |
| 90 | 95 | if ($num) |
@@ -96,15 +101,13 @@ discard block |
||
| 96 | 101 | if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
| 97 | 102 | { |
| 98 | 103 | // Do nothing |
| 99 | - } |
|
| 100 | - else |
|
| 104 | + } else |
|
| 101 | 105 | { |
| 102 | 106 | $labeltoshow=dol_trunc($obj->ref,18); |
| 103 | 107 | if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
| 104 | 108 | { |
| 105 | 109 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
| 106 | - } |
|
| 107 | - else |
|
| 110 | + } else |
|
| 108 | 111 | { |
| 109 | 112 | $disabled=0; |
| 110 | 113 | if (! $obj->fk_statut > 0) |
@@ -121,11 +124,12 @@ discard block |
||
| 121 | 124 | if ($hideunselectables && $disabled) |
| 122 | 125 | { |
| 123 | 126 | $resultat=''; |
| 124 | - } |
|
| 125 | - else |
|
| 127 | + } else |
|
| 126 | 128 | { |
| 127 | 129 | $resultat='<option value="'.$obj->rowid.'"'; |
| 128 | - if ($disabled) $resultat.=' disabled'; |
|
| 130 | + if ($disabled) { |
|
| 131 | + $resultat.=' disabled'; |
|
| 132 | + } |
|
| 129 | 133 | $resultat.='>'.$labeltoshow; |
| 130 | 134 | $resultat.='</option>'; |
| 131 | 135 | } |
@@ -138,8 +142,7 @@ discard block |
||
| 138 | 142 | $out.='</select>'; |
| 139 | 143 | $db->free($resql); |
| 140 | 144 | return $out; |
| 141 | - } |
|
| 142 | - else |
|
| 145 | + } else |
|
| 143 | 146 | { |
| 144 | 147 | dol_print_error($db); |
| 145 | 148 | return ''; |