diff --git a/Layout/default/Order/Form.php b/Layout/default/Order/Form.php index 26e6b93bf..1787f1bab 100644 --- a/Layout/default/Order/Form.php +++ b/Layout/default/Order/Form.php @@ -609,6 +609,15 @@
is("Admin", "netoperator")): ?> + id): ?> +
+ +
+ + +
+
+
@@ -662,6 +671,41 @@ }); }); + + id): ?> + $('#savetoivt-button').click(function() { + $('#savetoivt-button').prop("disabled", true); + $('#savetoivt-info').html(""); + $.get(" $order->id])?>", + {}, + function(data) { + console.log(data); + if(data.status == "OK") { + $('#savetoivt-info').removeClass("text-danger"); + $('#savetoivt-info').addClass("text-success"); + $('#savetoivt-info').text("Kunde erfolgreich an IVT übertragen!"); + $('#savetoivt-button').remove(); + } else { + $('#savetoivt-info').removeClass("text-success"); + $('#savetoivt-info').addClass("text-danger"); + if(data.reason) { + if(data.reason == "no-cust-num") { + $('#savetoivt-info').text("Inhaber und/oder Rechungsempfänger hat keine Kundennummer!"); + } + if(data.reason == "ivt-exist") { + $('#savetoivt-info').text("Kunde existiert bereits im IVT!"); + } + } else { + $('#savetoivt-info').text("Fehler bei übertragung."); + } + $('#savetoivt-button').prop("disabled", false); + } + }, + "json" + ); + }); + + $('#owner_id').change(function() { var val = $('#owner_id').val(); diff --git a/application/IvtCustomer/IvtCustomer.php b/application/IvtCustomer/IvtCustomer.php new file mode 100644 index 000000000..a5dbee8c4 --- /dev/null +++ b/application/IvtCustomer/IvtCustomer.php @@ -0,0 +1,86 @@ +log = mfLoghandler::singleton(); + $this->table = get_class($this); + $this->data = new stdClass(); + $this->table = "customers"; + + $this->db = new FronkDB(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + if(is_numeric($_)) { + $this->fetch($_); + } elseif(is_object($_)) { + $this->load($_); + } + } + + public function save() { + // get AUTO_INCREMENT value + $safe_ai = $this->getAutoIncrementId(); + if(!$safe_ai) { + return false; + } + $this->log->debug(__CLASS__.": auto increment value: $safe_ai"); + // save customer + + $fields = []; + $fields['id'] = $this->id; + foreach($this->data as $name => $value) { + $fields[$name] = $value; + } + + if(!$this->db->insert($this->table, $fields, $this->forcestr)) { + return false; + } + + // reset AUTO_INCREMENT value + if($this->setAutoIncrementId($safe_ai)) { + return true; + } + + $this->log->error(__CLASS__.": Unable to reset AUTO_INCREMENT value"); + return false; + + } + + private function getAutoIncrementId() { + $sql = "SELECT `AUTO_INCREMENT` as ai + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA = 'ivt_xinon' + AND TABLE_NAME = '".$this->table."'"; + $this->log->debug(__CLASS__.": $sql"); + $res = $this->db->query($sql); + if($this->db->num_rows($res)) { + $data = $this->db->fetch_object($res); + return $data->ai; + } + + } + + private function setAutoIncrementId($ai) { + $sql = "ALTER TABLE ".$this->table." AUTO_INCREMENT=$ai"; + $this->log->debug(__CLASS__.": $sql"); + + if($this->db->query($sql)) { + return true; + } + return false; + + } + + public function __debugInfo() { + $vars = get_object_vars($this); + if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; + if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; + return $vars; + } + +} \ No newline at end of file diff --git a/application/IvtCustomer/IvtCustomerController.php b/application/IvtCustomer/IvtCustomerController.php new file mode 100644 index 000000000..f3527e22b --- /dev/null +++ b/application/IvtCustomer/IvtCustomerController.php @@ -0,0 +1,107 @@ +request->order_id; + $order = new Order($order_id); + if(!$order->id) { + $this->layout()->setFlash("Bestellung nicht gefunden.", "error"); + $this->redirect("Order"); + } + + $contact = $order->$billingaddress; + if(!$contact) { + $contact = $order->owner; + } else { + $contact->customer_number = $order->owner->customer_number; + } + + if(!$contact->customer_number) { + $return = ['status' => 'error', 'reason' => "no-cust-num"]; + $this->returnJson($return); + } + + $ivtc = new IvtCustomer($contact->customer_number); + //var_dump($ivtc); + + if($ivtc->id) { + $return = ['status' => 'error', 'reason' => "ivt-exist"]; + $this->returnJson($return); + } + + + $ivtc->title = ""; + $ivtc->nick = ""; + $ivtc->pwd = ""; + $ivtc->bankcode = ""; + $ivtc->accountnumber = ""; + $ivtc->bill_row1 = ""; + $ivtc->bill_row2 = ""; + $ivtc->bill_row3 = ""; + $ivtc->bill_row4 = ""; + + $ivtc->id = $contact->customer_number; + $ivtc->company = str_replace("\r\n", " ", str_replace("\n", " ", $contact->company)); + if($contact->company) { + $ivtc->firstname = ""; + $ivtc->surname = str_replace("\r\n", " ", str_replace("\n", " ", $contact->company)); + } + $ivtc->UID = ""; // XXX + $ivtc->zip = $contact->zip; + $ivtc->location = $contact->city; + + // get housenumber + $m = []; + if(preg_match('/^(.+)\s+([^ ]+$)/', $contact->street, $m)) { + if($m[1]) { + $ivtc->street = $m[1]; + if($m[2]) { + $ivtc->housenumber = $m[2]; + } else { + $ivtc->housenumber = ""; + } + } + } else { + $ivtc->street = $contact->street; + $ivtc->housenumber = ""; + } + + $ivtc->phone = $contact->phone; + $ivtc->email = $contact->email; + + if($order->billing_type == "sepa") { + $ivtc->payment = 0; // 0 = sepa / 1 = rechnung + $ivtc->BIC = $order->bank_account_bic; + $ivtc->IBAN = $order->bank_account_iban; + } else { + $ivtc->payment = 1; // 0 = sepa / 1 = rechnung + $ivtc->BIC = ""; + $ivtc->IBAN = ""; + } + + $ivtc->paper_invoice = 0; + if(!$contact->email) { + $ivtc->paper_invoice = 1; + } + + $ivtc->MandatID = ($contract->spin) ? $contract->spin : 1; + + $ivtc->egn = 0; // 0=keine;1=pdf;2=cdr + $ivtc->accept_adver = $order->allow_contact; + $ivtc->accept_info = $order->allow_spin; + $ivtc->telephony_pricelist = 2; + $ivtc->extrainfo = $order->note; + + //var_dump($ivtc); + + + + if($ivtc->save()) { + $return = ['status' => 'OK', 'reason' => ""]; + } else { + $return = ['status' => 'error', 'reason' => "save"]; + } + $this->returnJson($return); + } +} \ No newline at end of file diff --git a/application/Order/Order.php b/application/Order/Order.php index 1acb40ff9..3fbc86339 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -46,6 +46,10 @@ class Order extends mfBaseModel { return $terminations; } + public function createIvtCustomer($data) { + + } + public function deletePositions() { if(!is_array($this->getProperty("products")) || !count($this->getProperty("products"))) { return true; diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index f22b2cf86..239ff85ba 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -166,7 +166,6 @@ class OrderController extends mfBaseController { return $new_filter; } - protected function addAction() { // TODO: filter by network permissions $this->layout()->setTemplate("Order/Form"); diff --git a/public/img/ajax-loader.gif b/public/img/ajax-loader.gif new file mode 100644 index 000000000..3288d1035 Binary files /dev/null and b/public/img/ajax-loader.gif differ