Add $YCO parameter (invoice numbering per year)

This commit is contained in:
jekkos-t520
2015-02-12 15:19:57 +01:00
parent 9e9a9a80a9
commit b5c33b4fcb
2 changed files with 17 additions and 0 deletions

View File

@@ -279,11 +279,18 @@ class Sales extends Secure_area
if (empty($invoice_number))
{
$invoice_number=$this->config->config['sales_invoice_format'];
// don't query if this variable isn't used
if (strstr($invoice_number,'$YCO'))
{
$invoice_number_year=$this->Sale->get_invoice_number_for_year(date('Y'));
$invoice_number=str_replace('$YCO',$invoice_number_year,$invoice_number);
}
}
$invoice_count=$this->Sale->get_invoice_count();
$invoice_number=str_replace('$CO',$invoice_count,$invoice_number);
$invoice_count=$this->Sale_suspended->get_invoice_count();
$invoice_number=str_replace('$SCO',$invoice_count,$invoice_number);
$invoice_number=strftime($invoice_number);
$customer_id=$this->sale_lib->get_customer();

View File

@@ -22,6 +22,16 @@ class Sale extends CI_Model
$this->db->where('invoice_number', $invoice_number);
return $this->db->get();
}
function get_invoice_number_for_year($year, $start_from = 0)
{
$this->db->select("COUNT( 1 ) AS invoice_number_year", FALSE);
$this->db->from('sales');
$this->db->where("DATE_FORMAT(sale_time, '%Y' ) = ", $year, FALSE);
$this->db->where("invoice_number IS NOT ", "NULL", FALSE);
$result = $this->db->get()->row_array();
return ($start_from + $result[ 'invoice_number_year' ] + 1);
}
function exists($sale_id)
{