function saveOrder() { $orderId = 0; $shippingCost = 5; $requiredField = array('hidShippingFirstName', 'hidShippingLastName', 'hidShippingAddress1', 'hidShippingCity', 'hidShippingPostalCode', 'hidPaymentFirstName', 'hidPaymentLastName', 'hidPaymentAddress1', 'hidPaymentCity', 'hidPaymentPostalCode'); if (checkRequiredPost($requiredField)) { extract($_POST); // make sure the first character in the // customer and city name are properly upper cased $hidShippingFirstName = ucwords($hidShippingFirstName); $hidShippingLastName = ucwords($hidShippingLastName); $hidPaymentFirstName = ucwords($hidPaymentFirstName); $hidPaymentLastName = ucwords($hidPaymentLastName); $hidShippingCity = ucwords($hidShippingCity); $hidPaymentCity = ucwords($hidPaymentCity); $cartContent = getCartContent(); $numItem = count($cartContent); // save order & get order id $sql = "INSERT INTO tbl_order(od_date, od_last_update, od_shipping_first_name, od_shipping_last_name, od_shipping_address1, \r\n\t\t od_shipping_address2, od_shipping_phone, od_shipping_state, od_shipping_city, od_shipping_postal_code, od_shipping_cost,\r\n od_payment_first_name, od_payment_last_name, od_payment_address1, od_payment_address2, \r\n\t\t\t\t\t\t\t\t\t od_payment_phone, od_payment_state, od_payment_city, od_payment_postal_code)\r\n VALUES (NOW(), NOW(), '{$hidShippingFirstName}', '{$hidShippingLastName}', '{$hidShippingAddress1}', \r\n\t\t\t\t '{$hidShippingAddress2}', '{$hidShippingPhone}', '{$hidShippingState}', '{$hidShippingCity}', '{$hidShippingPostalCode}', '{$shippingCost}',\r\n\t\t\t\t\t\t'{$hidPaymentFirstName}', '{$hidPaymentLastName}', '{$hidPaymentAddress1}', \r\n\t\t\t\t\t\t'{$hidPaymentAddress2}', '{$hidPaymentPhone}', '{$hidPaymentState}', '{$hidPaymentCity}', '{$hidPaymentPostalCode}')"; $result = dbQuery($sql); // get the order id $orderId = dbInsertId(); if ($orderId) { // save order items for ($i = 0; $i < $numItem; $i++) { $sql = "INSERT INTO tbl_order_item(od_id, pd_id, od_qty)\r\n\t\t\t\t\t\tVALUES ({$orderId}, {$cartContent[$i]['pd_id']}, {$cartContent[$i]['ct_qty']})"; $result = dbQuery($sql); } // update product stock for ($i = 0; $i < $numItem; $i++) { $sql = "UPDATE tbl_product \r\n\t\t\t\t SET pd_qty = pd_qty - {$cartContent[$i]['ct_qty']}\r\n\t\t\t\t\t\tWHERE pd_id = {$cartContent[$i]['pd_id']}"; $result = dbQuery($sql); } // then remove the ordered items from cart for ($i = 0; $i < $numItem; $i++) { $sql = "DELETE FROM tbl_cart\r\n\t\t\t\t WHERE ct_id = {$cartContent[$i]['ct_id']}"; $result = dbQuery($sql); } } } return $orderId; }
$peso = !empty($peso) ? "{$peso}" : "NULL"; $caja = !empty($caja) ? "{$caja}" : "NULL"; $mayoreo = !empty($mayoreo) ? "{$mayoreo}" : "NULL"; $codigo_barra = !empty($codigo_barra) ? "'{$codigo_barra}'" : "NULL"; $q = "SELECT * FROM articulo WHERE codigo = '{$codigo}' AND active = '1'"; $q1 = dbQuery($q); $q_tot = dbNumRows($q1); if ($q_tot > 0) { echo "existe"; //articulo existente } else { $w = "INSERT INTO articulo ("; $w .= "codigo, codant, marca_id, categoria_id,scategoria_id, sscategoria_id, nombre, fecha_alta, detalle, uni_med, peso, caja, mayoreo,codigo_barra)"; $w .= " VALUES ('{$codigo}',{$codigo_ant},{$marca}, {$cat}, {$scat}, {$sscat}, '{$nombre}',CURDATE(), '{$detalle}','{$uni_med}',{$peso},{$caja},{$mayoreo},{$codigo_barra})"; dbQuery($w); $idi = dbInsertId(); if ($idi > 0) { echo 'exito|' . $idi; } else { echo 'fracaso'; } } break; case "editar_articulo": $cat = $_GET['cat']; $scat = $_GET['scat']; $sscat = $_GET['sscat']; $codigo = $_GET['codigo']; $codigo_ant = $_GET['codigo_ant']; $marca = $_GET['marca']; $nombre = $_GET['nombre'];
$newZone['MinFilterPixels'] = intval(round($newZone['MinFilterPixels'] * $newA / $oldA)); $newZone['MaxFilterPixels'] = intval(round($newZone['MaxFilterPixels'] * $newA / $oldA)); $newZone['MinBlobPixels'] = intval(round($newZone['MinBlobPixels'] * $newA / $oldA)); $newZone['MaxBlobPixels'] = intval(round($newZone['MaxBlobPixels'] * $newA / $oldA)); $changes = getFormChanges($zone, $newZone, $types); if (count($changes)) { dbQuery("update Zones set " . implode(", ", $changes) . " WHERE MonitorId=? AND Id=?", array($mid, $zone['Id'])); } } } } elseif (!$user['MonitorIds']) { # FIXME This is actually a race condition. Should lock the table. $maxSeq = dbFetchOne("select max(Sequence) as MaxSequence from Monitors", "MaxSequence"); $changes[] = "Sequence = " . ($maxSeq + 1); dbQuery("insert into Monitors set " . implode(", ", $changes)); $mid = dbInsertId(); $zoneArea = $_REQUEST['newMonitor']['Width'] * $_REQUEST['newMonitor']['Height']; dbQuery("insert into Zones set MonitorId = ?, Name = 'All', Type = 'Active', Units = 'Percent', NumCoords = 4, Coords = ?, Area=?, AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MinAlarmPixels=?, MaxAlarmPixels=?, FilterX = 3, FilterY = 3, MinFilterPixels=?, MaxFilterPixels=?, MinBlobPixels=?, MinBlobs = 1", array($mid, sprintf("%d,%d %d,%d %d,%d %d,%d", 0, 0, $_REQUEST['newMonitor']['Width'] - 1, 0, $_REQUEST['newMonitor']['Width'] - 1, $_REQUEST['newMonitor']['Height'] - 1, 0, $_REQUEST['newMonitor']['Height'] - 1), $zoneArea, intval($zoneArea * 3 / 100), intval($zoneArea * 75 / 100), intval($zoneArea * 3 / 100), intval($zoneArea * 75 / 100), intval($zoneArea * 2 / 100))); //$view = 'none'; mkdir(ZM_DIR_EVENTS . '/' . $mid, 0755); $saferName = basename($_REQUEST['newMonitor']['Name']); symlink($mid, ZM_DIR_EVENTS . '/' . $saferName); if (isset($_COOKIE['zmGroup'])) { dbQuery("UPDATE Groups SET MonitorIds = concat(MonitorIds,'," . $mid . "') WHERE Id=?", array($_COOKIE['zmGroup'])); } } $restart = true; } if (ZM_OPT_X10) { $x10Changes = getFormChanges($x10Monitor, $_REQUEST['newX10Monitor']); if (count($x10Changes)) {
function doCompleteProfile() { $fname = $_POST['input_fname']; $lname = $_POST['input_lname']; $pwd = $_POST['input_username']; $pwd = $_POST['input_password']; $email = $_POST['input_email']; $phone = $_POST['phone']; $dob = $_POST['dob']; $gender = $_POST['gender']; $add = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = (int) $_POST['zipcode']; // $accno = (int)$_POST['accno']; $type = $_POST['acctype']; $pin = (int) $_POST['pin']; $errorMessage = ''; $sql = "SELECT fname FROM tbl_users WHERE fname = '{$fname}'"; $result = dbQuery($sql); if (dbNumRows($result) == 1) { $errorMessage = 'Username is already exist, please try another name.'; return $errorMessage; } //first check if account number is already register or not... $accno = rand(9999999999.0, 99999999999.0); $accno = strlen($accno) != 10 ? substr($accno, 0, 10) : $accno; /* $sql = "SELECT acc_no FROM tbl_accounts WHERE acc_no = $accno"; $result = dbQuery($sql); if (dbNumRows($result) == 1) { $errorMessage = 'Account number is already register.'; return $errorMessage; } */ $images = uploadProductImage('pic', SRV_ROOT . 'images/thumbnails/'); $thumbnail = $images['thumbnail']; $insert_id = 0; $sql = "INSERT INTO tbl_users (fname, lname, pwd, email, phone, gender, is_active, utype, pics, bdate)\n\t\t\tVALUES ('{$fname}', '{$lname}', PASSWORD('{$pwd}'), '{$email}', '{$phone}', '{$gender}', 'FALSE', 'USER', '{$thumbnail}', NOW())"; dbQuery($sql); $insert_id = dbInsertId(); //now create a user address. $sql = "INSERT INTO tbl_address (user_id, address, city, state, zipcode, country) \n\t\t\tVALUES ({$insert_id}, '{$add}', '{$city}', '{$state}', {$zip}, 'Bangladesh')"; dbQuery($sql); //and now create a account table entry... $sql = "INSERT INTO tbl_accounts (user_id, acc_no, type, balance, pin, status, bdate) \n\t\t\tVALUES ({$insert_id}, {$accno}, '{$type}', 0, {$pin}, 'INACTIVE', NOW())"; dbQuery($sql); //now send email //email it now. $subject = "Account Registration"; $to = $email; $msg_body = "Dear Customer,<br/><br/>\n\tThis is to inform you that your Account # {$accno} is register successfully with BAMS and currently in Inactive state. We will soon contact you once it get activate.<br/><br/>In case you need any further clarification for the same, please do get in touch with your Home Branch.<br/><br/>\n\tRegards,<br/>Admin, BAMS"; $mail_data = array('to' => $to, 'sub' => $subject, 'msg' => 'register', 'body' => $msg_body); //send_email($mail_data); header('Location: aregister.php'); exit; }
$vend = "SELECT vendedor_id FROM cliente WHERE id={$id_cliente}"; $rvend = dbQuery($vend); $vendrow = dbFetchAssoc($rvend); $id_vendedor = $vendrow['vendedor_id']; //PRimero cambio el estado del factura ya q este se cerrara en su totalidad para q se genere la factura $q = "UPDATE factura SET fecha_facturado=now(), status = 5, usuario_id={$usuario_id} WHERE id={$id_factura}"; dbQuery($q); //Ahora ya se procede a crear la factura con los datos del factura $w = "INSERT INTO factura ("; $w .= "status,factura_id,cliente_id,nit,vendedor_id,pago,transporte,facturara,nombre_empresa,direccion,flete,seguro,guatex,fecha_alta,usuario_id)"; $w .= " VALUES (1,{$id_factura},{$id_cliente},'{$nit}',{$id_vendedor},'{$pago}','{$transporte}','{$referencia}','{$cliente}', "; $w .= "'{$direccion}',{$flete},{$seguro}, {$guatex},now(),{$usuario_id} "; $w .= ")"; //echo $w; dbQuery($w); $id_fact = dbInsertId(); //ahora se crea el detalle de la factura, siempre jalando los datos q ya se tienen del factura $d = "SELECT * FROM factura_d WHERE active = 1 AND factura_id={$id_factura}"; $dq = dbQuery($d); while ($row = dbFetchAssoc($dq)) { $detalle_fact = "INSERT INTO factura_d (factura_id, articulo_id, cantidad, precio_local, precio_local_sin_iva, total, total_sin_iva,fecha_alta,usuario_id) "; $detalle_fact .= "VALUES(\n\t\t\t\t\t\t{$id_fact}, \n\t\t\t\t\t\t" . $row['articulo_id'] . ", \n\t\t\t\t\t\t" . $row['cantidad'] . ", \n\t\t\t\t\t\t" . $row['precio_local'] . ", \n\t\t\t\t\t\t" . $row['precio_local_sin_iva'] . ", \n\t\t\t\t\t\t" . $row['total'] . ", \n\t\t\t\t\t\t" . $row['total_sin_iva'] . ", \n\t\t\t\t\t\tnow(),\n\t\t\t\t\t\t{$usuario_id}\n\t\t\t\t\t)"; dbQuery($detalle_fact); } echo 'exito|'; break; case "cerrar_factura": $estanteria = "SELECT * FROM bodega WHERE active = 1 AND estanteria = 1"; $estanteria1 = dbQuery($estanteria); $estanteria2 = dbFetchAssoc($estanteria1); $bodega_estanteria = $estanteria2['id'];
//FIN calculo de gautex, flete y seguro/// $r = "SELECT sum(fd.total) as total_factura, \n\t\t\t(SELECT IFNULL(sum(monto),0) FROM abonos WHERE active=1 AND factura_id=fd.factura_id) as monto_abono\n\t\t\tFROM factura_d as fd\n\t\t\tWHERE fd.active = 1 AND fd.factura_id ={$id_factura}"; $r2 = dbQuery($r); $r3 = dbFetchAssoc($r2); $restante = round(floatval($total) - floatval($r3['monto_abono']), 2); //echo $restante.' |'.$monto; if (floatval($monto) > $restante) { $retorno = 'fracaso||'; } else { $w = "INSERT INTO abonos ("; $w .= "no_recibo,factura_id,fecha_abono,fecha_comision,monto,forma_de_pago,fecha_cheque_postfechado,fecha_alta,usuario_id)"; $w .= " VALUES ({$no_recibo},{$id_factura},'{$fecha_abono}','{$fecha_comision}',{$monto},'{$forma_de_pago}','{$fecha_cheque_postfechado}',now(),{$usuario_id} "; $w .= ")"; //echo $w; dbQuery($w); $id_abono = dbInsertId(); $retorno = 'exito|' . $id_abono . '|' . $fecha_abono; } $uf = "SELECT sum(fd.total) as total_factura, \n\t\t\t(SELECT IFNULL(sum(monto),0) FROM abonos WHERE active=1 AND factura_id=fd.factura_id) as monto_abono\n\t\t\tFROM factura_d as fd\n\t\t\tWHERE fd.active = 1 AND fd.factura_id ={$id_factura}"; $uf2 = dbQuery($uf); $uf3 = dbFetchAssoc($uf2); $uf_restante = floatval($total) - floatval($uf3['monto_abono']); if ($uf_restante <= 0) { $q = "UPDATE factura SET fecha_modifica=now(), fecha_de_pago=now(), usuario_id={$usuario_id}, status=3 WHERE id={$id_factura}"; $q1 = dbQuery($q); } echo $retorno; break; case "obtener_detalles": $id_factura = $_GET['id_fact']; ?>
$usuario_id = $_SESSION['id_user']; switch ($_GET['fnc']) { case "generar_nc": $id_fact = $_GET['id_fact']; $nombre = $_GET['nombre']; $direccion = $_GET['direccion']; $nit = $_GET['nit']; $codigo_cliente = $_GET['codigo_cliente']; $id_cliente = $_GET['id_cliente']; $w = "INSERT INTO nota_credito ("; $w .= "status,factura_id,cliente_id,codigo_cliente,nombre_cliente,direccion_cliente,nit_cliente,fecha_alta)"; $w .= " VALUES (1,{$id_fact},{$id_cliente},'{$codigo_cliente}','{$nombre}','{$direccion}','{$nit}',now() "; $w .= ")"; //echo $w; $check = dbQuery($w); $id_nc = dbInsertId(); if ($check) { echo 'exito|' . $id_nc; } else { echo 'fracaso|' . $id_nc; } break; case "eliminar_linea": $id_nota_credito_d = $_GET['id_nota_credito_d']; $q = "UPDATE nota_credito_d SET active = 0, fecha_modifica=now(),usuario_id={$usuario_id} WHERE id={$id_nota_credito_d}"; $result = dbQuery($q); if ($result) { echo "exito"; } else { echo "fracaso"; }