From 87d2f032c1500e29ff481f246359eb170d2d8104 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 7 Oct 2021 22:31:12 +0200 Subject: [PATCH] added send customer to IVT --- Layout/default/Order/Form.php | 44 +++++++ application/IvtCustomer/IvtCustomer.php | 86 ++++++++++++++ .../IvtCustomer/IvtCustomerController.php | 107 ++++++++++++++++++ application/Order/Order.php | 4 + application/Order/OrderController.php | 1 - public/img/ajax-loader.gif | Bin 0 -> 3208 bytes 6 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 application/IvtCustomer/IvtCustomer.php create mode 100644 application/IvtCustomer/IvtCustomerController.php create mode 100644 public/img/ajax-loader.gif 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 0000000000000000000000000000000000000000..3288d1035d70bb86517e2c233f1a904e41f06b29 GIT binary patch literal 3208 zcmc(iX;4#H9>pJdFE7h`I{IF)0|5<6L}(j=N}5%L009EB2nYfyF)E0PvIqo$u!IC; z4PgyY5|S9AEh38G)(9eq4TbH7_UHg@yWrlIJ$6smIADL7s^P;_O;ykRc9soXl`UC*LwQJXkii*0rx|*7rI2=x7WaRkx_~XZqFJ8R3c=2Kg zf@aSAv8+BJ8+^hyay>(QR@t*blbKzsf0}bscEqRc5Hd3o(-N5RyW=zWB*zQw6Zh>* z2CROCDAbu#D`)S|J_o(lL9Yn3l*+8RdiRD_>iNz$#_IAzCna&Wl5 zSF_(rRCDD!wi#i8oAm&jYtn2_@VB%2-H*G%bN#|(6R6N?wM)3u`PiGzwuX7qmTgyF zpE)h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