! -> Note
$ -> Affected files
+31-Jul-2009 Janusz Dobrowolski
+! Merged changes from main trunk 2.1.3-2.1.4 (see below)
+$ /admin/attachments.php
+ /inventory/purchasing_data.php
+ /includes/db/manufacturing.inc
+ /gl/manage/bank_accounts.php
+ /gl/includes/db/gl_db_banking.inc
+ /gl/includes/db/gl_db_trans.inc
+ /purchasing/includes/purchasing_db.inc
+ /purchasing/manage/suppliers.php
+ /purchasing/view/view_grn.php
+ /purchasing/includes/db/invoice_db.inc
+ /purchasing/view/view_supp_payment.php
+ /reporting/reports_main.php
+ /reporting/includes/doctext.inc
+ /reporting/includes/doctext2.inc
+ /reporting/includes/header2.inc
+ /reporting/includes/pdf_report.inc
+ /reporting/rep101.php
+ /reporting/rep109.php
+ /reporting/rep201.php
+ /reporting/rep304.php
+ /reporting/rep709.php
+ /sales/includes/db/cust_trans_db.inc
+ /sales/create_recurrent_invoices.php
+ /sales/sales_order_entry.php
+ /sales/view/view_receipt.php
27-Jul-2009 Janusz Dobrowolski
# Fixed default selection in popup
/sales/inquiry/sales_deliveries_view.php
/sales/inquiry/sales_orders_view.php
+------------------------------- Release 2.1.4 ----------------------------------
+30-Jul-2009 Joe Hunt
+! Release 2.1.4
+$ config.php
+# Bad right margin on Tax Report (papersize A4)
+$ /reporting/rep709.php
+# [0000146] Purch data description with a ' (apostrophe) fails
+$ /inventory/purchasing_data.php
+ /purchasing/includes/purchasing_db.inc
+
+28-Jul-2009 Joe Hunt
+# Bugs in sending documents as email. Seems to land in the spam filter due to bad text and scrambled name on attached documents
+$ /reporting/rep109.php
+ /reporting/includes/doctext.inc
+ /reporting/includes/doctext2.inc
+ /reporting/includes/header2.inc
+ /reporting/includes/pdf_report.inc
+
+18-Jul-2009 Joe Hunt
+# When saving a Payment to a Customer in Bank Payments (normally payment to suppliers) it was saved with wrong sign in debtor_trans (very rare).
+$ /sales/includes/db/cust_trans_db.inc
+# Wrong presentation in customer/supplier balance if using bank payments for customers and bank deposits for suppliers (very rare)
+$ /reporting/rep101.php
+ /reporting/rep201.php
+
+13-Jul-2009 Joe Hunt
+# Bug in Tax Inquiry and Tax Report when entering in Journal Entry
+$ /gl/includes/db/gl_db_banking.inc
+ /gl/includes/db/gl_db_trans.inc
+ /reporting/rep709.php
+! Comments should follow templates and recurrent invoices.
+$ /sales/create_recurrent_invoices.php
+ /sales/sales_order_entry.php
+
+12-Jul-2009 Joe Hunt
+# Wrong presentation of left to allocate if discount was given
+$ /sales/view/view_receipt.php
+ /purchasing/view/view_supp_payment.php
+
+11-Jul-2009 Joe Hunt
+! Improved Inventory Sales Report. Now by Customer and quantities as well.
+$ /reporting/rep304.php
+ /reporting/reports_main.php
+
+10-Jul-2009 Joe Hunt
+# [0000142] Purchase Order use the same header as Sales Order
+$ /reporting/includes/doctext.inc
+ /reporting/includes/doctext2.inc
+# Bug in demand qty
+$ /includes/db/manufacturing.inc
+
+10-Jul-2009 Janusz Dobrowolski
+# [0000141] Attachment view/download bug.
+$ /admin/attachments.php
+# [0000140] Numeric format bug in credit limit input.
+$ /purchasing/manage/suppliers.php
+# [0000143] Bad format of PO popup window (jackel7007).
+$ /purchasing/view/view_grn.php
+
+09-Jul-2009 Janusz Dobrowolski
+# [0000139] Change of bank account type after creation should not be allowed.
+$ /gl/manage/bank_accounts.php
+
+01-Jul-2009 Joe Hunt
+# Guess what :) [0000137] Material Cost Averaging Problem (again again again) when voiding.
+$ /purchasing/includes/db/invoice_db.inc
+
+26-Jun-2009 Joe Hunt
+# [0000137] Material Cost Averaging Problem (again again) when voiding.
+$ /purchasing/includes/db/invoice_db.inc
+
------------------------------- Release 2.1.3 ----------------------------------
25-Jun-2009 Joe Hunt
! Release 2.1.3
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
+if (isset($_GET['vw']))
+ $view_id = $_GET['vw'];
+else
$view_id = find_submit('view');
if ($view_id != -1)
{
$row = get_attachment($view_id);
if ($row['filename'] != "")
{
- $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream';
- header("Content-type: ".$type);
- header('Content-Length: '.$row['filesize']);
- if ($type == 'application/octet-stream')
- header('Content-Disposition: attachment; filename='.$row['filename']);
- else
- header("Content-Disposition: inline");
- echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']);
- exit();
+ if(in_ajax()) {
+ $Ajax->popup($_SERVER['PHP_SELF'].'?vw='.$view_id);
+ } else {
+ $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream';
+ header("Content-type: ".$type);
+ header('Content-Length: '.$row['filesize']);
+ if ($type == 'application/octet-stream')
+ header('Content-Disposition: attachment; filename='.$row['filename']);
+ else
+ header("Content-Disposition: inline");
+ echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']);
+ exit();
+ }
}
}
+if (isset($_GET['dl']))
+ $download_id = $_GET['dl'];
+else
+ $download_id = find_submit('download');
-$download_id = find_submit('download');
if ($download_id != -1)
{
$row = get_attachment($download_id);
if ($row['filename'] != "")
{
- $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream';
- header("Content-type: ".$type);
- header('Content-Length: '.$row['filesize']);
- header('Content-Disposition: attachment; filename='.$row['filename']);
- echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']);
- exit();
+ if(in_ajax()) {
+ $Ajax->redirect($_SERVER['PHP_SELF'].'?dl='.$download_id);
+ } else {
+ $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream';
+ header("Content-type: ".$type);
+ header('Content-Length: '.$row['filesize']);
+ header('Content-Disposition: attachment; filename='.$row['filename']);
+ echo file_get_contents($comp_path."/".user_company(). "/attachments/".$row['unique_name']);
+ exit();
+ }
}
}
// Main Title
$app_title = "FrontAccounting";
// application version
- $version = "2.2m3 CVS";
+ $version = "2.2m4 CVS";
// Build for development purposes
$build_version = date("d.m.Y", filemtime("$path_to_root/CHANGELOG.txt"));
$amount = $gl_item->amount;
$ex_rate = get_exchange_rate_from_home_currency($currency, $date_);
- add_gl_tax_details($gl_item->code_id, $trans_type, $trans_no, $amount,
+ add_gl_tax_details($gl_item->code_id, $trans_type, $trans_no, -$amount,
$ex_rate, $date_, $memo_);
}
if(!$tax_type) return; // $gl_code is not tax account
$tax = get_tax_type($tax_type);
- if ($gl_code == $tax['sales_gl_code'])
- $amount = -$amount;
+ //if ($gl_code == $tax['sales_gl_code'])
+ // $amount = -$amount;
// we have to restore net amount as we cannot know the base amount
if ($tax['rate'] == 0) {
// display_warning(_("You should not post gl transactions
$todate = date2sql($to);
$sql = "SELECT
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output,
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable,
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input,
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, amount*ex_rate)) collectible,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, 0, amount*ex_rate)) collectible,
taxrec.rate,
ttype.id,
ttype.name
}
// store tax details if the gl account is a tax account
add_gl_tax_details($journal_item->code_id,
- $trans_type, $trans_id, -$journal_item->amount, 1, $date_, $memo_);
+ ($journal_item->amount < 0.0 ? 2 : 1), $trans_id, -$journal_item->amount, 1, $date_, $memo_);
}
if ($new) {
if ($is_bank_to)
{
add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref,
- $reversingDate, $journal_item->amount,
+ $reversingDate, -$journal_item->amount,
0, "", get_company_currency(),
"Cannot insert a destination bank transaction");
}
// store tax details if the gl account is a tax account
add_gl_tax_details($journal_item->code_id,
- $trans_type, $trans_id, $journal_item->amount, 1, $reversingDate, $memo_);
+ ($journal_item->amount < 0.0 ? 2 : 1), $trans_id, $journal_item->amount, 1, $date, $memo_);
}
add_comments($trans_type, $trans_id_reverse, $reversingDate, $memo_);
}
hidden('selected_id', $selected_id);
hidden('account_code');
+ hidden('account_type');
hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);
set_focus('bank_account_name');
}
text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100);
-bank_account_types_list_row(_("Account Type:"), 'account_type', null);
-
+if ($is_editing)
+{
+ label_row(_("Account Type:"), bank_account_types::name($_POST['account_type']));
+}
+else
+{
+ bank_account_types_list_row(_("Account Type:"), 'account_type', null);
+}
if ($is_editing)
{
label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']);
}
$stock_qty = $qoh_stock[$stock_id];
if ($stock_qty == NULL) $stock_qty = 0;
- if ($qty < $stock_qty) return $demand;
+ if ($qty <= $stock_qty) return $demand;
$bom = $bom_list[$stock_id];
if ($bom == NULL) {
$sql = "SELECT parent, component, quantity FROM ".TB_PREF."bom WHERE parent = '$stock_id'";
$sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
conversion_factor, supplier_description) VALUES (";
$sql .= "'".$_POST['supplier_id']."', '" . $_POST['stock_id'] . "', " .
- input_num('price') . ", '" . $_POST['suppliers_uom'] . "', " .
- input_num('conversion_factor') . ", '" . $_POST['supplier_description'] . "')";
+ input_num('price',0) . ", '" . $_POST['suppliers_uom'] . "', " .
+ input_num('conversion_factor') . ", " . db_escape($_POST['supplier_description']) . ")";
db_query($sql,"The supplier purchasing details could not be added");
display_notification(_("This supplier purchasing data has been added."));
} else
{
- $sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price') . ",
+ $sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price',0) . ",
suppliers_uom='" . $_POST['suppliers_uom'] . "',
conversion_factor=" . input_num('conversion_factor') . ",
- supplier_description='" . $_POST['supplier_description'] . "'
+ supplier_description=" . db_escape($_POST['supplier_description']) . "
WHERE stock_id='" . $_POST['stock_id'] . "' AND
supplier_id='$selected_id'";
db_query($sql,"The supplier purchasing details could not be updated");
//----------------------------------------------------------------------------------------
+function get_matching_invoice_item($stock_id, $po_item_id)
+{
+ $sql = "SELECT *, tran_date FROM ".TB_PREF."supp_invoice_items, ".TB_PREF."supp_trans
+ WHERE supp_trans_type = 20 AND stock_id = '$stock_id' AND po_detail_item_id = $po_item_id
+ AND supp_trans_no = trans_no";
+ $result = db_query($sql, "Cannot retreive supplier transaction detail records");
+ return db_fetch($result);
+}
+
function void_supp_invoice($type, $type_no)
{
begin_transaction();
+ $trans = get_supp_trans($type_no, $type);
+
void_bank_trans($type, $type_no, true);
void_gl_trans($type, $type_no, true);
$batch = get_grn_batch_from_item($details_row["grn_item_id"]);
$grn = get_grn_batch($batch);
if ($type == 21) // credit note 2009-06-14 Joe Hunt Must restore the po and grn
- {
+ { // We must get the corresponding invoice item to check for price chg.
+ $match = get_matching_invoice_item($details_row["stock_id"], $details_row["po_detail_item_id"]);
+ if ($match !== false)
+ $mat_cost = update_average_material_cost($grn["supplier_id"], $details_row["stock_id"],
+ $match["unit_price"], -$details_row["quantity"], sql2date($match['tran_date']), $match['tran_date'] !== $trans['tran_date']);
+ else
+ $mat_cost = update_average_material_cost($grn["supplier_id"], $details_row["stock_id"],
+ $details_row["FullUnitPrice"], -$details_row["quantity"], $old_date, $old[1] !== $trans['tran_date']);
$sql = "UPDATE ".TB_PREF."purch_order_details
- SET quantity_ordered = quantity_ordered + ".-$details_row["quantity"].",
- quantity_received = quantity_received + ".-$details_row["quantity"]."
+ SET quantity_ordered = quantity_ordered + ".-$details_row["quantity"].", ";
+ if ($match !== false)
+ $sql .= "act_price=".$match['unit_price'].", ";
+ $sql .= "quantity_received = quantity_received + ".-$details_row["quantity"]."
WHERE po_detail_item = ".$details_row["po_detail_item_id"];
db_query($sql, "a purchase order details record could not be updated. This receipt of goods has not been processed ");
$sql = "UPDATE ".TB_PREF."grn_items SET qty_recd=qty_recd+".-$details_row["quantity"]."
WHERE id=".$details_row["grn_item_id"];
db_query($sql);
- }
- $diff = get_diff_in_home_currency($grn["supplier_id"], $old_date, $date_, $old[2],
- $details_row["FullUnitPrice"]);
- // Only adjust the avg for the diff
- $mat_cost = update_average_material_cost(null, $details_row["stock_id"],
- $diff, -$details_row["quantity"], $old_date, true);
-
+ }
+ else
+ {
+ $diff = get_diff_in_home_currency($grn["supplier_id"], $old_date, sql2date($trans['tran_date']), $old[2],
+ $details_row["FullUnitPrice"]);
+ // Only adjust the avg for the diff
+ $mat_cost = update_average_material_cost(null, $details_row["stock_id"],
+ $diff, -$details_row["quantity"], $old_date, true);
+ }
$deliveries = get_deliveries_between($details_row["stock_id"], $old_date, $date_);
if ($deliveries[0] != 0) // have deliveries been done during the period?
{
{
$sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
conversion_factor, supplier_description) VALUES ('$supplier_id', '$stock_id',
- $price, '$uom', 1, '$description')";
+ $price, '$uom', 1, ".db_escape($description).")";
db_query($sql,"The supplier purchasing details could not be added");
return;
}
if ($uom != "")
$sql .= ",suppliers_uom='$uom'";
if ($description != "")
- $sql .= ",supplier_description='$description'";
+ $sql .= ",supplier_description=".db_escape($description);
$sql .= " WHERE stock_id='$stock_id' AND supplier_id='$supplier_id'";
db_query($sql,"The supplier purchasing details could not be updated");
return true;
.db_escape($_POST['contact']). ", "
.db_escape($_POST['supp_account_no']). ", "
.db_escape($_POST['bank_account']). ", "
- .db_escape($_POST['credit_limit']). ", "
+ .input_num('credit_limit',0). ", "
.db_escape($_POST['dimension_id']). ", "
.db_escape($_POST['dimension2_id']). ", "
.db_escape($_POST['curr_code']). ", "
include($path_to_root . "/purchasing/includes/po_class.inc");
include($path_to_root . "/includes/session.inc");
-page(_("View Purchase Order Delivery"), true);
+
+$js = "";
+if ($use_popup_windows)
+ $js .= get_js_open_window(900, 500);
+page(_("View Purchase Order Delivery"), true, false, "", $js);
include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
label_cells(_("Supplier's Currency"), $receipt['SupplierCurrCode'], "class='tableheader2'");
}
if ($show_both_amounts)
- label_cells(_("Amount"), number_format2(-$receipt['ov_amount'], user_price_dec()), "class='tableheader2'");
+ label_cells(_("Amount"), number_format2(-$receipt['Total'], user_price_dec()), "class='tableheader2'");
label_cells(_("Reference"), $receipt['ref'], "class='tableheader2'");
end_row();
comments_display_row(22, $trans_no);
// now display the allocations for this payment
if (!$voided)
{
- display_allocations_from(payment_person_types::supplier(), $receipt['supplier_id'], 22, $trans_no, -$receipt['ov_amount']);
+ display_allocations_from(payment_person_types::supplier(), $receipt['supplier_id'], 22, $trans_no, -$receipt['Total']);
}
end_page(true);
{
$doc_Cust_no = _("Cust no");
$doc_Date = _("Date");
- $doc_Charge_To = _("Charge To");
- $doc_Delivered_To = _("Delivered To");
+ if ($doctype == 8) // Purchase Order
+ {
+ $doc_Charge_To = _("Order To");
+ $doc_Delivered_To = _("Charge To");
+ }
+ else
+ {
+ $doc_Charge_To = _("Charge To");
+ $doc_Delivered_To = _("Delivered To");
+ }
$doc_Shipping_Company = _("Shipping Company");
if ($doctype == 9)
$doc_Due_Date = _("Delivery Date");
}
if (isset($emailtype))
{
- $doc_Dear_Sirs = _("Dear Sirs");
+ $doc_Dear_Sirs = _("Dear");
$doc_AttachedFile = _("Attached you will find ");
$doc_Kindest_regards = _("Kindest regards");
$doc_Payment_Link = _("You can pay through");
{
$doc_Cust_no = "Cust no";
$doc_Date = "Date";
- $doc_Charge_To = "Charge To";
- $doc_Delivered_To = "Delivered To";
+ if ($doctype == 8) // Purchase Order
+ {
+ $doc_Charge_To = "Order To";
+ $doc_Delivered_To = "Charge To";
+ }
+ else
+ {
+ $doc_Charge_To = "Charge To";
+ $doc_Delivered_To = "Delivered To";
+ }
$doc_Shipping_Company = "Shipping Company";
if ($doctype == 9)
$doc_Due_Date = "Delivery Date";
}
if (isset($emailtype))
{
- $doc_Dear_Sirs = "Dear Sirs";
+ $doc_Dear_Sirs = "Dear";
$doc_AttachedFile = "Attached you will find ";
$doc_Kindest_regards = "Kindest regards";
$doc_Payment_Link = "You can pay through";
if (($doctype == 10 || $doctype == 12) && $this->company['legal_text'] != "")
{
$this->TextWrap($ccol, $this->row, $right - $ccol, $this->company['legal_text'], 'C');
- $this->NewLine();
+// $this->NewLine();
}
$this->Font();
$temp = $iline6 - $this->lineHeight - 2;
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
+$page_security = 8;
//include_once($path_to_root . "reporting/includes/class.pdf.inc");
include_once(dirname(__FILE__)."/class.pdf.inc");
include_once(dirname(__FILE__)."/printer_class.inc");
}
// do not use standard filenames or your sensitive company data
// are world readable
- $fname = $dir.'/'.uniqid('').'.pdf';
+ if ($email == 1)
+ $fname = $dir.'/'.$this->filename;
+ else
+ $fname = $dir.'/'.uniqid('').'.pdf';
$this->Output($fname, 'F');
if ($email == 1)
{
}
require_once($path_to_root . "/reporting/includes/class.mail.inc");
$mail = new email($this->company['coy_name'], $this->company['email']);
- $from = $this->company['coy_name'] . " <" . $this->company['email'] . ">";
- if ($myrow['email'] == '') $myrow['email'] = $myrow['contact_email'];
+ if (!isset($myrow['email']) || $myrow['email'] == '')
+ $myrow['email'] = $myrow['contact_email'];
$to = $myrow['DebtorName'] . " <" . $myrow['email'] . ">";
$msg = $doc_Dear_Sirs . " " . $myrow['DebtorName'] . ",\n\n" . $doc_AttachedFile . " " . $subject .
"\n\n";
- if ($myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links
+ if (isset($myrow['dimension_id']) && $myrow['dimension_id'] > 0 && $doctype == 10) // helper for payment links
{
if ($myrow['dimension_id'] == 1)
{
$mail->text($msg . $sender);
$mail->attachment($fname);
$ret = $mail->send();
- if (1 == 1) // just for fun and for debugging purposes!!
- {
- $from = str_replace("<", "(", $from);
- $from = str_replace(">", ")", $from);
- $to = str_replace("<", "(", $to);
- $to = str_replace(">", ")", $to);
- $msg2 = "<br>From: " . $from;
- $msg2 .= "<br>To: " . $to;
- $msg2 .= "<br>Subject: " . $subject;
- $msg2 .= "<br>Msg: " . nl2br($msg);
- $msg2 .= nl2br($sender) . "<br>";
- $msg2 .= "<br>Filepath: " . $fname . "<br>Filename: " . $this->filename . "<br>";
- }
if (!$ret)
display_error(_("Sending document by email failed"));
else
display_notification($this->title . " " . $myrow['reference'] . " "
. _("has been sent by email."));
+ unlink($fname);
}
else
{
else
$item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
*/
- if ($trans['type'] == 10)
+ if ($trans['type'] == 10 || $trans['type'] == 1)
$item[3] = $item[0] + $item[1] - $item[2];
else
$item[3] = $item[0] - $item[1] + $item[2];
$myrow['contact_email'] = $branch['email'];
$myrow['DebtorName'] = $branch['br_name'];
}
+ $myrow['reference'] = $i;
$rep->End($email, $doc_Invoice_no . " " . $i, $myrow);
}
}
else
$item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
*/
- if ($trans['type'] == 20)
+ if ($trans['type'] == 20 || $trans['type'] == 2)
$item[3] = $item[0] + $item[1] - $item[2];
else
$item[3] = $item[0] - $item[1] + $item[2];
print_inventory_sales();
-function getTransactions($category, $location, $from, $to)
+function getTransactions($category, $location, $fromcust, $from, $to)
{
$from = date2sql($from);
$to = date2sql($to);
".TB_PREF."stock_master.description,
".TB_PREF."stock_moves.loc_code,
".TB_PREF."debtor_trans.debtor_no,
+ ".TB_PREF."debtors_master.name AS debtor_name,
".TB_PREF."stock_moves.tran_date,
- -".TB_PREF."stock_moves.qty*".TB_PREF."stock_moves.price*(1-".TB_PREF."stock_moves.discount_percent) AS amt,
- -".TB_PREF."stock_moves.qty *(".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost) AS cost
+ SUM(-".TB_PREF."stock_moves.qty) AS qty,
+ SUM(-".TB_PREF."stock_moves.qty*".TB_PREF."stock_moves.price*(1-".TB_PREF."stock_moves.discount_percent)) AS amt,
+ SUM(-".TB_PREF."stock_moves.qty *(".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost)) AS cost
FROM ".TB_PREF."stock_master,
".TB_PREF."stock_category,
".TB_PREF."debtor_trans,
+ ".TB_PREF."debtors_master,
".TB_PREF."stock_moves
WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id
AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
-
+ AND ".TB_PREF."debtor_trans.debtor_no=".TB_PREF."debtors_master.debtor_no
AND ".TB_PREF."stock_moves.type=".TB_PREF."debtor_trans.type
AND ".TB_PREF."stock_moves.trans_no=".TB_PREF."debtor_trans.trans_no
AND ".TB_PREF."stock_moves.tran_date>='$from'
$sql .= " AND ".TB_PREF."stock_master.category_id = '$category'";
if ($location != 'all')
$sql .= " AND ".TB_PREF."stock_moves.loc_code = '$location'";
- //$sql .= " AND SUM(".TB_PREF."stock_moves.qty) != 0
- $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
- ".TB_PREF."stock_master.stock_id";
+ if ($fromcust != -1)
+ $sql .= " AND ".TB_PREF."debtors_master.debtor_no = $fromcust";
+ $sql .= " GROUP BY ".TB_PREF."stock_master.stock_id, ".TB_PREF."debtors_master.name ORDER BY ".TB_PREF."stock_master.category_id,
+ ".TB_PREF."stock_master.stock_id, ".TB_PREF."debtors_master.name";
return db_query($sql,"No transactions were returned");
}
$to = $_POST['PARAM_1'];
$category = $_POST['PARAM_2'];
$location = $_POST['PARAM_3'];
- $detail = $_POST['PARAM_4'];
+ $fromcust = $_POST['PARAM_4'];
$comments = $_POST['PARAM_5'];
$destination = $_POST['PARAM_6'];
if ($destination)
else
$loc = get_location_name($location);
- $cols = array(0, 100, 250, 350, 450, 515);
+ if ($fromcust == reserved_words::get_all_numeric())
+ $fromc = _('All');
+ else
+ $fromc = get_customer_name($fromcust);
+
+ $cols = array(0, 75, 175, 250, 300, 375, 450, 515);
- $headers = array(_('Category'), '', _('Sales'), _('Cost'), _('Contribution'));
+ $headers = array(_('Category'), _('Description'), _('Customer'), _('Qty'), _('Sales'), _('Cost'), _('Contribution'));
+ if ($fromcust != reserved_words::get_all_numeric())
+ $headers[2] = '';
- $aligns = array('left', 'left', 'right', 'right', 'right');
+ $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
$params = array( 0 => $comments,
1 => array('text' => _('Period'),'from' => $from, 'to' => $to),
2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
- 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
+ 3 => array('text' => _('Location'), 'from' => $loc, 'to' => ''),
+ 4 => array('text' => _('Customer'), 'from' => $fromc, 'to' => ''));
$rep = new FrontReport(_('Inventory Sales Report'), "InventorySalesReport", user_pagesize());
$rep->Info($params, $cols, $headers, $aligns);
$rep->Header();
- $res = getTransactions($category, $location, $from, $to);
+ $res = getTransactions($category, $location, $fromcust, $from, $to);
$total = $grandtotal = 0.0;
$total1 = $grandtotal1 = 0.0;
$total2 = $grandtotal2 = 0.0;
- $amt = $cost = $cb = 0;
- $catt = $stock_id = $stock_desc = '';
+ $catt = '';
while ($trans=db_fetch($res))
{
if ($catt != $trans['cat_description'])
{
if ($catt != '')
{
- if ($detail)
- {
- $rep->NewLine(2, 3);
- $rep->TextCol(0, 2, _('Total'));
- }
- $rep->AmountCol(2, 3, $total, $dec);
- $rep->AmountCol(3, 4, $total1, $dec);
- $rep->AmountCol(4, 5, $total2, $dec);
- if ($detail)
- {
- $rep->Line($rep->row - 2);
- $rep->NewLine();
- }
+ $rep->NewLine(2, 3);
+ $rep->TextCol(0, 4, _('Total'));
+ $rep->AmountCol(4, 5, $total, $dec);
+ $rep->AmountCol(5, 6, $total1, $dec);
+ $rep->AmountCol(6, 7, $total2, $dec);
+ $rep->Line($rep->row - 2);
+ $rep->NewLine();
$rep->NewLine();
$total = $total1 = $total2 = 0.0;
}
$rep->TextCol(0, 1, $trans['category_id']);
- $rep->TextCol(1, 2, $trans['cat_description']);
+ $rep->TextCol(1, 6, $trans['cat_description']);
$catt = $trans['cat_description'];
- if ($detail)
- $rep->NewLine();
- }
- if ($stock_id != $trans['stock_id'])
- {
- if ($stock_id != '')
- {
- if ($detail)
- {
- $rep->NewLine();
- $rep->fontsize -= 2;
- $rep->TextCol(0, 1, $stock_id);
- $rep->TextCol(1, 2, $stock_desc);
- $rep->AmountCol(2, 3, $amt, $dec);
- $rep->AmountCol(3, 4, $cost, $dec);
- $rep->AmountCol(4, 5, $cb, $dec);
- $rep->fontsize += 2;
- }
- $amt = $cost = $cb = 0;
- }
- $stock_id = $trans['stock_id'];
- $stock_desc = $trans['description'];
+ $rep->NewLine();
}
+
$curr = get_customer_currency($trans['debtor_no']);
$rate = get_exchange_rate_from_home_currency($curr, sql2date($trans['tran_date']));
$trans['amt'] *= $rate;
- $amt += $trans['amt'];
- $cost += $trans['cost'];
- $cb1 = $trans['amt'] - $trans['cost'];
- $cb += $cb1;
+ $cb = $trans['amt'] - $trans['cost'];
+ $rep->NewLine();
+ $rep->fontsize -= 2;
+ $rep->TextCol(0, 1, $trans['stock_id']);
+ if ($fromcust == reserved_words::get_all_numeric())
+ {
+ $rep->TextCol(1, 2, $trans['description']);
+ $rep->TextCol(2, 3, $trans['debtor_name']);
+ }
+ else
+ $rep->TextCol(1, 3, $trans['description']);
+ $rep->AmountCol(3, 4, $trans['qty'], get_qty_dec($trans['stock_id']));
+ $rep->AmountCol(4, 5, $trans['amt'], $dec);
+ $rep->AmountCol(5, 6, $trans['cost'], $dec);
+ $rep->AmountCol(6, 7, $cb, $dec);
+ $rep->fontsize += 2;
$total += $trans['amt'];
$total1 += $trans['cost'];
- $total2 += $cb1;
+ $total2 += $cb;
$grandtotal += $trans['amt'];
$grandtotal1 += $trans['cost'];
- $grandtotal2 += $cb1;
- }
- if ($detail)
- {
- $rep->NewLine();
- $rep->fontsize -= 2;
- $rep->TextCol(0, 1, $stock_id);
- $rep->TextCol(1, 2, $stock_desc);
- $rep->AmountCol(2, 3, $amt, $dec);
- $rep->AmountCol(3, 4, $cost, $dec);
- $rep->AmountCol(4, 5, $cb, $dec);
- $rep->fontsize += 2;
-
- $rep->NewLine(2, 3);
- $rep->TextCol(0, 2, _('Total'));
- }
- $rep->AmountCol(2, 3, $total, $dec);
- $rep->AmountCol(3, 4, $total1, $dec);
- $rep->AmountCol(4, 5, $total2, $dec);
- if ($detail)
- {
- $rep->Line($rep->row - 2);
- $rep->NewLine();
+ $grandtotal2 += $cb;
}
+ $rep->NewLine(2, 3);
+ $rep->TextCol(0, 4, _('Total'));
+ $rep->AmountCol(4, 5, $total, $dec);
+ $rep->AmountCol(5, 6, $total1, $dec);
+ $rep->AmountCol(6, 7, $total2, $dec);
+ $rep->Line($rep->row - 2);
+ $rep->NewLine();
$rep->NewLine(2, 1);
- $rep->TextCol(0, 2, _('Grand Total'));
- $rep->AmountCol(2, 3, $grandtotal, $dec);
- $rep->AmountCol(3, 4, $grandtotal1, $dec);
- $rep->AmountCol(4, 5, $grandtotal2, $dec);
+ $rep->TextCol(0, 4, _('Grand Total'));
+ $rep->AmountCol(4, 5, $grandtotal, $dec);
+ $rep->AmountCol(5, 6, $grandtotal1, $dec);
+ $rep->AmountCol(6, 7, $grandtotal2, $dec);
$rep->Line($rep->row - 4);
$rep->NewLine();
while ($trans=db_fetch($transactions))
{
- if (in_array($trans['trans_type'], array(11,20,1))) {
+ if (in_array($trans['trans_type'], array(11,20))) {
$trans['net_amount'] *= -1;
$trans['amount'] *= -1;
}
$rep->Header();
}
}
- if (in_array($trans['trans_type'], array(0,2,10,11))) {
+ if (in_array($trans['trans_type'], array(2,10,11))) {
$taxes[$trans['tax_type_id']]['taxout'] += $trans['amount'];
$taxes[$trans['tax_type_id']]['out'] += $trans['net_amount'];
} else {
new ReportParam(_('End Date'),'DATEENDM'),
new ReportParam(_('Inventory Category'),'CATEGORIES'),
new ReportParam(_('Location'),'LOCATIONS'),
- new ReportParam(_('Detailed Report'),'YES_NO'),
+ new ReportParam(_('Customer'),'CUSTOMERS_NO_FILTER'),
new ReportParam(_('Comments'),'TEXTBOX'),
new ReportParam(_('Destination'),'DESTINATION')));
$reports->addReport(_('Inventory'),305,_('&GRN Valuation Report'),
$doc->due_date = get_invoice_duedate($doc->customer_id, $doc->document_date);
$doc->reference = references::get_next($doc->trans_type);
- $doc->Comments='';
+ //$doc->Comments='';
foreach ($doc->line_items as $line_no=>$item) {
$line = &$doc->line_items[$line_no];
$SQLDueDate = "0000-00-00";
else
$SQLDueDate = date2sql($due_date);
+
+ if ($trans_type == systypes::bank_payment())
+ $Total = -$Total;
if ($new) {
$trans_no = get_next_trans_no($trans_type);
} else
$doc->due_date = $doc->document_date;
$doc->reference = references::get_next($doc->trans_type);
- $doc->Comments='';
+ //$doc->Comments='';
foreach($doc->line_items as $line_no => $line) {
$doc->line_items[$line_no]->qty_done = 0;
}
end_row();
start_row();
label_cells(_("Payment Currency"), $receipt['curr_code'], "class='tableheader2'");
-label_cells(_("Amount"), price_format($receipt['ov_amount']), "class='tableheader2'");
+label_cells(_("Amount"), price_format($receipt['Total'] - $receipt['ov_discount']), "class='tableheader2'");
label_cells(_("Discount"), price_format($receipt['ov_discount']), "class='tableheader2'");
end_row();
start_row();