db->queryAll("SELECT DISTINCT sop_number FROM {$this->db->tblInvoiceImport} ii INNER JOIN {$this->db->tblInvoice} i ON ii.sop_number = i.number"); if (count($duplicatedInvoices )) { sendDeveloperEmail('Duplicate Invoice in generating queue', $duplicatedInvoices ); $this->db->query("DELETE FROM {$this->db->tblInvoiceImport} WHERE sop_number IN (SELECT number FROM {$this->db->tblInvoice})"); } do { $this->invoiceId = (int)$this->db->queryOne("SELECT sop_number FROM {$this->db->tblInvoiceImport}"); $invoiceRecords = $this->db->queryAll("SELECT DISTINCT customer_id, type, customer_name, address, address2, city, state, zip, contact_person, invoice_date FROM {$this->db->tblInvoiceImport} WHERE sop_number = " . $this->invoiceId); if (count($invoiceRecords) > 1) { sendDeveloperEmail('Duplicate Invoice data in one invoce', $invoiceRecords); return false; } else { break; } } while (true); return $this->invoiceId; } public function getInvoiceRecords() { $invoiceType = $this->db->queryOne("SELECT type FROM {$this->db->tblInvoiceImport} WHERE sop_number = " . $this->invoiceId . " LIMIT 1"); if ($invoiceType == 'exchange') { $sql = "SELECT *, DATE_FORMAT(invoice_date, '%m/%e/%Y') AS invoice_date_formatted, l.nrds_id AS customer_nrds_id FROM {$this->db->tblInvoiceImport} ii INNER JOIN {$this->db->tblLocation} l ON ii.customer_id = l.id WHERE sop_number = " . $this->invoiceId; } else { $sql = "SELECT *, DATE_FORMAT(invoice_date, '%m/%e/%Y') AS invoice_date_formatted, m.nrds_id AS customer_nrds_id, l.nrds_id AS location_nrds_id FROM {$this->db->tblInvoiceImport} ii INNER JOIN {$this->db->tblMember} m ON ii.customer_id = m.id LEFT JOIN {$this->db->tblLocation} l ON m.id_location = l.id WHERE sop_number = " . $this->invoiceId; } $invoiceRecords = $this->db->queryAll($sql); return $invoiceRecords; } public function clearInvoiceRecords() { $this->db->query("DELETE FROM {$this->db->tblInvoiceImport} WHERE sop_number = " . $this->invoiceId); //vdie("DELETE FROM {$this->db->tblInvoiceImport} WHERE sop_number = " . $this->invoiceId); return true; } } ?>