Timestamp start: 9:30 How to calculate and display the margin by orders. Made on clean QC6.3
file: database/_fields.php add a field: 'fPurchasePrice' in arrays: $aProductsFields, $aOrdersProductsFields, $aOrdersTempFields
file: database/translations/xx.php add new values:
$lang['Purchase_price'] = "Purchase price"; $lang['Margin'] = "Margin";
file: templates/admin/products-form.php
behind the:
<input type="text" name="mPrice" value="<?php if( isset( $aData['mPrice'] ) ) echo $aData['mPrice']; ?>" class="inputr" size="10" /> <?php echo $config['currency_symbol']; ?>
add a new input with description and spaces:
<?php echo $lang['Purchase_price'].': ';?> <input type="text" name="fPurchasePrice" value="<?php if(isset($aData['fPurchasePrice'])) echo $aData['fPurchasePrice'];?>" class="inputr" size="10"/> <?php echo $config['currency_symbol'];?> <?php echo $lang['Margin'].': '.((isset($aData['mPrice'])&&is_numeric($aData['mPrice'])&&isset($aData['fPurchasePrice'])&&is_numeric($aData['fPurchasePrice']))?displayPrice(normalizePrice($aData['mPrice']-$aData['fPurchasePrice'])):null);?>
file: templates/admin/products.php
under:
<td class="pages"><?php echo $lang['Pages']; ?></td>
add:
<td class="price"><?php echo $lang['Purchase_price'];?> [<?php echo $config['currency_symbol'];?>]</td>
and under:
<td class="price"><a href="?p=<?php echo $p; ?><?php if( isset( $sPhrase ) ) echo '&sPhrase='.$sPhrase; ?><?php if( isset( $iPageSearch ) ) echo '&iPageSearch='.$iPageSearch; ?>&sSort=price"><?php echo $lang['Price']; ?></a> [<?php echo $config['currency_symbol']; ?>]</td>
add:
<td class="price"><?php echo $lang['Margin'];?> [<?php echo $config['currency_symbol'];?>]</td>
remember to expand the colspans with two fields
file: core/products-admin.php
function: saveProduct($aForm) under:
if( is_numeric( str_replace( ',', '.', $aForm['mPrice'] ) ) ) $aForm['mPrice'] = normalizePrice( $aForm['mPrice'] );
add:
if(is_numeric(str_replace(',','.',$aForm['fPurchasePrice']))) $aForm['fPurchasePrice']=normalizePrice($aForm['fPurchasePrice']);
function listProductsAdmin($iList=null); under:
<td class="pages"> '.$aData['sPages'].' </td>
add:
<td class="price"> <input type="text" name="aPurchasePrices['.$aData['iProduct'].']" value="'.$aData['fPurchasePrice'].'" class="inputr" size="8" /> </td>
and under:
<td class="price"> <input type="text" name="aPrices['.$aData['iProduct'].']" value="'.$aData['mPrice'].'" class="inputr" size="8" /> </td>
add:
<td class="price">'. ((isset($aData['mPrice'])&&is_numeric($aData['mPrice'])&&isset($aData['fPurchasePrice'])&&is_numeric($aData['fPurchasePrice']))?displayPrice(normalizePrice($aData['mPrice']-$aData['fPurchasePrice'])):null).' </td>
file: core/products.php
function: generateCache(); under:
if( !isset( $aValue['mPrice'] ) ) $aValue['mPrice'] = null;
add:
if(!isset($aValue['fPurchasePrice'])) $aValue['fPurchasePrice']=null;
function: saveProdudcs($aForm); under:
if( is_numeric( str_replace( ',', '.', $aForm['aPrices'][$iProduct] ) ) ) $aForm['aPrices'][$iProduct] = normalizePrice( trim( $aForm['aPrices'][$iProduct] ) ); else $aForm['aPrices'][$iProduct] = trim( $aForm['aPrices'][$iProduct] );
add:
if(is_numeric(str_replace(',','.',$aForm['aPurchasePrices'][$iProduct]))) $aForm['aPurchasePrices'][$iProduct]=normalizePrice(trim($aForm['aPurchasePrices'][$iProduct])); else $aForm['aPurchasePrices'][$iProduct]=trim($aForm['aPurchasePrices'][$iProduct]);
under:
if( $aForm['aPrices'][$iProduct] != $aData['mPrice'] ){ $this->aProducts[$iProduct]['mPrice'] = $aForm['aPrices'][$iProduct]; $bChanged = true; }
add:
if($aForm['aPurchasePrices'][$iProduct]!=$aData['fPurchasePrice']){ $this->aProducts[$iProduct]['fPurchasePrice']=$aForm['aPurchasePrices'][$iProduct]; $bChanged=true; }
The handling of purchasePrice and margin (saving, displaying in list- and products view) is finished.
Timestamp: 9:25 coffee break. Timestamp: 9:40 end of break
Now I start with saving the purchasePrice into the order.
file: core/orders.php function: saveBasket($aData,$bAdd=null) in line:
$aBasket[$iOrder][$iProduct] = Array( 'iQuantity' => (int) $iQuantity, 'fPrice' => $oProduct->aProducts[$iProduct]['mPrice'], 'sName' => $oProduct->aProducts[$iProduct]['sName'] );
add a field:
'fPurchasePrice'=>$oProduct->aProducts[$iProduct]['fPurchasePrice']
function: addOrder($aForm) in the line:
file_put_contents( DB_ORDERS_PRODUCTS, serialize( compareArrays( $this->aOrdersProductsFields, Array( 'iElement' => (int) $iElement++, 'iOrder' => $aForm['iOrder'], 'iProduct' => $aData['iProduct'], 'iQuantity' => $aData['iQuantity'], 'fPrice' => $aData['fPrice'], 'sName' => $aData['sName'] ) ) )."\n", FILE_APPEND );
add a field:
'fPurchasePrice'=>$aData['fPurchasePrice']
Timestamp 10:00 saving the purchasePrice to order complete. Now we smoke a cigarette and drink some coffe. Timestamp 10:10 end of break
Now we calculate the totalMargin of the order
file: core/orders.php head of class Orders with variables under:
public $fProductsSummary = null;
add:
public $fPurchaseSummary = null;
function: generateProducts($iOrder) under:
$this->fProductsSummary = null;
add:
$this->fPurchaseSummary=null;
under:
$this->fProductsSummary += $this->aProducts[$aData['iElement']]['fPrice'] * $this->aProducts[$aData['iElement']]['iQuantity'];
add:
$this->aProducts[$aData['iElement']]['fPurchaseSummary']=isset($this->aProducts[$aData['iElement']]['fPurchasePrice'])?normalizePrice($this->aProducts[$aData['iElement']]['fPurchasePrice']*$this->aProducts[$aData['iElement']]['iQuantity']):0; $this->fPurchaseSummary+=isset($this->aProducts[$aData['iElement']]['fPurchasePrice'])?$this->aProducts[$aData['iElement']]['fPurchasePrice']*$this->aProducts[$aData['iElement']]['iQuantity']:0;
under:
if( isset( $this->fProductsSummary ) ){ $this->fProductsSummary = normalizePrice( $this->fProductsSummary ); }
add:
if(isset($this->fPurchaseSummary)) $this->fPurchaseSummary=normalizePrice($this->fPurchaseSummary);
file: core/orders-admin.php function: listProductsAdmin($iOrder) under:
$this->aOrders[$iOrder]['sOrderSummary'] = $this->aOrders[$iOrder]['sProductsSummary'] = displayPrice( $this->fProductsSummary );
add:
$this->aOrders[$iOrder]['fPurchaseSummary']=$this->aOrders[$iOrder]['fPurchaseSummary']=$this->fPurchaseSummary; $this->aOrders[$iOrder]['fTotalMargin']=$this->aOrders[$iOrder]['fOrderSummary']-$this->aOrders[$iOrder]['fPurchaseSummary']; $this->aOrders[$iOrder]['sTotalMargin']=displayPrice(normalizePrice($this->aOrders[$iOrder]['fTotalMargin']));
file: templates/admin/orders-form.php under:
$sOrderSummary = isset( $oOrder->aOrders[$iOrder]['sOrderSummary'] ) ? $oOrder->aOrders[$iOrder]['sOrderSummary'] : null;
add:
$sTotalMargin=isset($oOrder->aOrders[$iOrder]['sTotalMargin'])?$oOrder->aOrders[$iOrder]['sTotalMargin']:null;
under:
<tr> <td colspan="4" class="info"> <?php echo $lang['Summary']; ?> </td> <td colspan="2" class="summary"> <?php echo $sOrderSummary; ?> </td> </tr>
add:
<tr> <td colspan="4" class="info"> <?php echo $lang['Margin'];?> </td> <td colspan="2" class="summary"> <?php echo $sTotalMargin;?> </td> </tr>
Timestamp: 10:55 The TotalMargin in single Order view is finished. Coffe + cigarette. Timestamp: 11:10 end of break
file: templates/admin/orders.php under:
<td class="date"><?php echo $lang['Date']; ?></td>
add:
<td class="price"><?php echo $lang['Summary']; ?></td> <td class="price"><?php echo $lang['Margin']; ?></td>
remember to expand the colspans with two fields
file: core/orders-admin.php function: listOrdersAdmin($iList=null) under:
$aData = $this->aOrders[$aOrders[$i]];
add:
$this->generateProducts($aData['iOrder']);
behind:
<td class="date">'.$aData['sDate'].'</td>
add:
<td class="date">'.$this->fProductsSummary.'</td> <td class="date">'.displayPrice(normalizePrice(($this->fProductsSummary-$this->fPurchaseSummary))).'</td>
Timestamp: 11:40 End of work
@Cachousam, if you mean, you want to pay me for this, my payPal account is the email address You used to write me today. How many? I don't know. It is Your move now :-)
» Quick.Cart v6.xboboo :-) |