munty_arjun Posted March 13, 2010 Share Posted March 13, 2010 Hi everyone, I was wondering if anyone could help me with a php calculation by taking data from a mysql database. Basically I am working with an opensource software called bamboo invoice, but it has got a major flaw in reports section, where it calculates the final amount of all invoices and includes Value added tax in all of them, even in those where VAT is not applicable. In my database there is a separate table named taxable in which number 1 is shown if VAT is applicable otherwise it shows a 0 if no VAT is applicable. Now I have found the following code where the main problem persist, but as I am not very good in php I was wondering if I can get any help from you guys. Basically in the below code i want this equation to occur - Rather than just multiplying the tax1_rate by the amount, I want the program to build an equation of if and else. For instance, I want the program to calculate in this manner – if ‘taxable’ is 1 then ‘amount’ * ‘tax1_rate/100’ else ‘amount’ function getDetailedData($start_date, $end_date) { $this->db->select('SUM('.$this->db->dbprefix('invoice_items').'.amount*'.$this->db->dbprefix('invoices').'.tax1_rate/100 * '.$this->db->dbprefix('invoice_items').'.quantity) as tax1_collected', FALSE); $this->db->join('invoices', 'invoices.client_id = clients.id'); $this->db->join('invoice_items', 'invoices.id = invoice_items.invoice_id'); $this->db->where('dateIssued >= "' . $start_date . '" and dateIssued <= "' . $end_date . '"'); $this->db->orderby('clients.name'); $this->db->groupby('name'); return $this->db->get('clients'); } Over here rather than just multiplying the tax1_rate by the amount and quantity, I want the program to build an equation of if and else. For instance, I want the program to calculate in this manner – if ‘taxable’ is 1 then ‘amount’ * ‘quntity’ * ‘tax1_rate/100’ else ‘amount’ * ‘quantity’ // -------------------------------------------------------------------- function getSummaryData($start_date, $end_date) { $this->db->select('SUM(('.$this->db->dbprefix('invoice_items').'.amount*'.$this->db->dbprefix('invoice_items').'.quantity)*'.$this->db->dbprefix('invoices').'.tax1_rate/100) AS tax1_collected', FALSE); $this->db->join('invoices', 'invoices.client_id = clients.id'); $this->db->join('invoice_items', 'invoices.id = invoice_items.invoice_id'); $this->db->where('dateIssued >= ', $start_date); $this->db->where('dateIssued <= ', $end_date); return $this->db->get('clients')->row(); } Hope this makes sense. Any help on this matter would be highly appreciatable. Thanks Link to comment https://forums.phpfreaks.com/topic/195104-else-and-if-statement-in-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.