static function create($order_id, $lang) { $sql = sql_query("select * from orders\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere (id = '" . $order_id . "')"); $data = sql_fetch_object($sql); if (!$data->id) { return 0; } $l = new lang("invoice", $lang); //zjistime radu a cislo faktury //rady mame pro CR - czk ; CR - eur ; SK - eur //prefix mame ulozeny v configu //cislo nacteme podle nejvyssiho cisla predchozi faktury $prefix = get_shop_config("invoice_prefix_" . $data->i_country . "_" . $data->cur); $s_n = sql_query("select number from invoices\n\t\t\t\t\t\t\t\t\t\t\t\t\twhere (number_prefix = '" . $prefix . "')\n\t\t\t\t\t\t\t\t\t\t\t\t\torder by id desc\n\t\t\t\t\t\t\t\t\t\t\t\t\tlimit 1"); $d_n = sql_fetch_object($s_n); $number = $d_n->number + 1; //format na 5 cifer $number = sprintf("%05d", $number); $cur_value = get_shop_config("cur_" . $data->cur . "_value"); //vytvorime fakturu ------------- $country = $l->t("country_" . $data->i_country); $s = sql_query("insert into invoices\n\t\t\t\t\t\t\t\t\t\t\t\t(order_id, user, create_date, number, number_prefix, c_name, c_street,\n\t\t\t\t\t\t\t\t\t\t\t\tc_city, c_zip, c_country, invoice_country, price, cur, cur_value, pay_method,\n\t\t\t\t\t\t\t\t\t\t\t\tcompany_name, company_ic, company_dic)\n\t\t\t\t\t\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t\t\t\t\t('" . $data->id . "', '" . $data->user . "', '" . time() . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $number . "', '" . $prefix . "', '" . $data->i_name . "', '" . $data->i_street . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $data->i_city . "', '" . $data->i_zip . "', '" . $country . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $data->i_country . "', '" . $data->price . "', '" . $data->cur . "', '" . $cur_value . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $data->pay_method . "', '" . $data->company_name . "', '" . $data->company_ic . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $data->company_dic . "')"); if ($s) { $id = mysql_insert_id(); //ulozime jednotlive polozky faktury $s = sql_query("select merchant, item, quantity, price_per_one, tax\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfrom orders_items\n\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere (order_id = '" . $order_id . "')"); while ($d = sql_fetch_object($s)) { if ($d->merchant == 'audiolx') { $s_p = sql_query("select name from merchant_audiolibrix\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere (id = '" . $d->item . "')"); } if ($d->merchant == 'self') { $s_p = sql_query("select name from selfpublishing\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere (id = '" . $d->item . "')"); } $d_p = sql_fetch_object($s_p); $s_i = sql_query("insert into invoices_items\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(invoice_id, name, quantity, price_per_one, tax)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t('" . $id . "', '" . $d_p->name . "', '" . $d->quantity . "', '" . $d->price_per_one . "', '" . $d->tax . "')"); } if ($s_i) { return $id; } } return 0; }
function save() { //zjistime jestli objednavka obsahuje polozky z audiolibrix $audiolibrix_state = 0; foreach ($this->items as $item) { if ($item->type == 'audiolx') { $audiolibrix_state = 1; } } //zda-li je zaplacena, u nulovych je rovnou $is_paid = 0; if (!$this->is_order_payment()) { $is_paid = 1; } //ok, ulozime $sql = sql_query("insert into orders\n\t\t\t\t\t\t\t\t\t\t\t\t\t(time, user,\n\t\t\t\t\t\t\t\t\t\t\t\t\ti_name, i_street, i_city, i_zip, i_country,\n\t\t\t\t\t\t\t\t\t\t\t\t\taudiolibrix_state, is_paid,\n\t\t\t\t\t\t\t\t\t\t\t\t\tnote, company_name, company_ic, company_dic)\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t\t\t\t\t\t('" . time() . "', '" . $this->me->uid . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->i_name, "just") . "', \n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->i_street, "just") . "', '" . clear($this->i_city, "just") . "', \n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->i_zip, "just") . "', '" . clear($this->i_country, "just") . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $audiolibrix_state . "', '" . $is_paid . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->note, "just") . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->company_name, "just") . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->company_ic, "just") . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . clear($this->company_dic, "just") . "')"); if ($sql) { $id = mysql_insert_id(); //ulozeni itemu ------------------------ $sum = 0; foreach ($this->items as $item) { $s = sql_query("insert into orders_items\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(order_id, merchant, item, quantity, price_per_one, tax)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t('" . $id . "', '" . $item->type . "', '" . $item->item . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t '" . $item->quantity . "', '" . $item->price() . "', '" . $item->tax . "')"); $sum += $item->quantity * $item->price(); } if ($s) { if ($this->cur == 'eur') { $cur_value = get_shop_config("cur_eur_value"); } $s = sql_query("update orders\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tset price = '" . $sum . "', cur_value = '" . $cur_value . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere (id = '" . $id . "')"); $this->state = "ordered"; return $id; } else { //pokud neco nevyslo, zrusime order $this->cancel_order($id); } } $this->msg->set_text($this->l->t("save_error"), "error"); return 0; }