/** * Store a newly created stock in storage. * * @return Response */ public function store() { $stock = new Purchase(); $stock->item = Input::get('item'); $stock->selling_price = Input::get('selling_price'); $stock->price = Input::get('purchase_price'); $stock->quantity = Input::get('quantity'); $stock->status = Input::get('status'); $stock->account = Input::get('account'); $stock->save(); return Redirect::route('purchases.index'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Purchase(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Purchase'])) { $model->attributes = $_POST['Purchase']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function saveInPurchaseTable() { try { $input = Input::all(); $purchaseTable = new Purchase(); $purchaseTable->user_id = Auth::user()->id; $purchaseTable->branch_id = $input['branch_id']; $purchaseTable->comments = $input['comments']; $purchaseTable->status = 'pendiente'; $purchaseTable->save(); return $purchaseTable; } catch (Exception $e) { die('No se pudo guardar el registro en compras.'); } }
/** * Orders admin flow handlers */ function orders_list() { global $Shopp, $Orders; $db = DB::get(); $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'per_page' => false, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); if (!current_user_can(SHOPP_USERLEVEL)) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } if ($page == "shopp-orders" && !empty($deleting) && !empty($selected) && is_array($selected)) { foreach ($selected as $selection) { $Purchase = new Purchase($selection); $Purchase->load_purchased(); foreach ($Purchase->purchased as $purchased) { $Purchased = new Purchased($purchased->id); $Purchased->delete(); } $Purchase->delete(); } } $statusLabels = $this->Settings->get('order_status'); if (empty($statusLabels)) { $statusLabels = array(''); } $txnStatusLabels = array('PENDING' => __('Pending', 'Shopp'), 'CHARGED' => __('Charged', 'Shopp'), 'REFUNDED' => __('Refunded', 'Shopp'), 'VOID' => __('Void', 'Shopp')); if ($update == "order" && !empty($selected) && is_array($selected)) { foreach ($selected as $selection) { $Purchase = new Purchase($selection); $Purchase->status = $newstatus; $Purchase->save(); } } $Purchase = new Purchase(); if (!empty($start)) { $startdate = $start; list($month, $day, $year) = explode("/", $startdate); $starts = mktime(0, 0, 0, $month, $day, $year); } if (!empty($end)) { $enddate = $end; list($month, $day, $year) = explode("/", $enddate); $ends = mktime(23, 59, 59, $month, $day, $year); } $pagenum = absint($pagenum); if (empty($pagenum)) { $pagenum = 1; } if (!$per_page || $per_page < 0) { $per_page = 20; } $start = $per_page * ($pagenum - 1); $where = ''; if (!empty($status) || $status === '0') { $where = "WHERE status='{$status}'"; } if (!empty($s)) { $s = stripslashes($s); if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER) > 0) { foreach ($props as $search) { $keyword = !empty($search[2]) ? $search[2] : $search[3]; switch (strtolower($search[1])) { case "txn": $where .= (empty($where) ? "WHERE " : " AND ") . "transactionid='{$keyword}'"; break; case "gateway": $where .= (empty($where) ? "WHERE " : " AND ") . "gateway LIKE '%{$keyword}%'"; break; case "cardtype": $where .= (empty($where) ? "WHERE " : " AND ") . "cardtype LIKE '%{$keyword}%'"; break; case "address": $where .= (empty($where) ? "WHERE " : " AND ") . "(address LIKE '%{$keyword}%' OR xaddress='%{$keyword}%')"; break; case "city": $where .= (empty($where) ? "WHERE " : " AND ") . "city LIKE '%{$keyword}%'"; break; case "province": case "state": $where .= (empty($where) ? "WHERE " : " AND ") . "state='{$keyword}'"; break; case "zip": case "zipcode": case "postcode": $where .= (empty($where) ? "WHERE " : " AND ") . "postcode='{$keyword}'"; break; case "country": $where .= (empty($where) ? "WHERE " : " AND ") . "country='{$keyword}'"; break; } } if (empty($where)) { $where .= (empty($where) ? "WHERE " : " AND ") . " (id='{$s}' OR CONCAT(firstname,' ',lastname) LIKE '%{$s}%')"; } } elseif (strpos($s, '@') !== false) { $where .= (empty($where) ? "WHERE " : " AND ") . " email='{$s}'"; } else { $where .= (empty($where) ? "WHERE " : " AND ") . " (id='{$s}' OR CONCAT(firstname,' ',lastname) LIKE '%{$s}%')"; } } if (!empty($starts) && !empty($ends)) { $where .= (empty($where) ? "WHERE " : " AND ") . ' (UNIX_TIMESTAMP(created) >= ' . $starts . ' AND UNIX_TIMESTAMP(created) <= ' . $ends . ')'; } $ordercount = $db->query("SELECT count(*) as total,SUM(total) AS sales,AVG(total) AS avgsale FROM {$Purchase->_table} {$where} ORDER BY created DESC"); $query = "SELECT * FROM {$Purchase->_table} {$where} ORDER BY created DESC LIMIT {$start},{$per_page}"; $Orders = $db->query($query, AS_ARRAY); $num_pages = ceil($ordercount->total / $per_page); $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum)); $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp'), 'iif' => __('Intuit® QuickBooks.iif', 'Shopp')); $formatPref = $Shopp->Settings->get('purchaselog_format'); if (!$formatPref) { $formatPref = 'tab'; } $columns = array_merge(Purchase::exportcolumns(), Purchased::exportcolumns()); $selected = $Shopp->Settings->get('purchaselog_columns'); if (empty($selected)) { $selected = array_keys($columns); } include "{$this->basepath}/core/ui/orders/orders.php"; }
function process() { global $Shopp; if (empty($_POST)) { new ShoppError(__('Payment could not be confirmed, this order cannot be processed.', 'Shopp'), '2co_transaction_error', SHOPP_COMM_ERR); exit; } session_unset(); session_destroy(); // Load the cart for the correct order $Shopp->Cart = new Cart(); $Shopp->Cart->session = $_POST['vendor_order_id']; session_start(); $Shopp->Cart->load($Shopp->Cart->session); if ($this->settings['verify'] == "on" && !$this->validate($_POST['key'])) { new ShoppError(__('The order submitted to 2Checkout could not be verified.', 'Shopp'), '2co_validation_error', SHOPP_TRXN_ERR); exit; } if ($_POST['credit_card_processed'] == "N") { new ShoppError(__('The payment failed. Please try your order again with a different payment method.', 'Shopp'), '2co_processing_error', SHOPP_TRXN_ERR); exit; } if (!$Shopp->Cart->validorder()) { new ShoppError(__('There is not enough customer information to process the order.', 'Shopp'), 'invalid_order', SHOPP_TRXN_ERR); exit; } $Order = $Shopp->Cart->data->Order; $Order->Totals = $Shopp->Cart->data->Totals; $Order->Items = $Shopp->Cart->contents; $Order->Cart = $Shopp->Cart->session; $Order->Customer->save(); $Order->Billing->customer = $Order->Customer->id; $Order->Billing->cardtype = "2Checkout"; $Order->Billing->save(); $Order->Shipping->customer = $Order->Customer->id; $Order->Shipping->save(); $Purchase = new Purchase(); $Purchase->customer = $Order->Customer->id; $Purchase->billing = $Order->Billing->id; $Purchase->shipping = $Order->Shipping->id; $Purchase->copydata($Order->Customer); $Purchase->copydata($Order->Billing); $Purchase->copydata($Order->Shipping, 'ship'); $Purchase->copydata($Order->Totals); $Purchase->freight = $Order->Totals->shipping; $Purchase->gateway = "2Checkout"; $Purchase->transtatus = "CHARGED"; $Purchase->transactionid = $_POST['order_number']; $Purchase->ip = $Shopp->Cart->ip; $Purchase->save(); foreach ($Shopp->Cart->contents as $Item) { $Purchased = new Purchased(); $Purchased->copydata($Item); $Purchased->purchase = $Purchase->id; if (!empty($Purchased->download)) { $Purchased->keygen(); } $Purchased->save(); if ($Item->inventory) { $Item->unstock(); } } return $Purchase; }
/** * Post manual additions transacton form */ static function addManually($params) { extract($params); $ipn_url = Config::get('project.paypal_ipn_url'); $params = array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'product_id' => Input::get('product_id'), 'plan_id' => Input::get('plan_id'), 'pay_id' => Input::get('pay_id'), 'stripe_token' => Input::get('stripe_token'), 'paypal_sub_id' => Input::get('paypal_sub_id'), 'amount' => Input::get('amount'), 'affiliate_id' => Input::get('affiliate_id')); $members[] = array('email' => $email, 'fname' => $first_name, 'lname' => $last_name); $data = array(); if ($members) { foreach ($members as $member) { // Add or get buyer if ($buyer = Buyer::getOrCreate($member)) { // Get Plan $plan = Plan::find($plan_id); if ($plan and !$plan->is_oto) { // Add purchase for the buyer $purchase = new Purchase(); $purchase->buyer_id = $buyer->id; $purchase->product_id = $product_id; $purchase->plan_id = $plan_id; $purchase->stripe_token = $stripe_token ? $stripe_token : NULL; $purchase->paypal_sub_id = $paypal_sub_id ? $paypal_sub_id : NULL; $purchase->pay_method = 2; $purchase->affiliate_id = $affiliate_id; // If method is Stripe if ($pay_id and DKHelpers::GetPayMethod($pay_id) == 'Stripe') { $purchase->pay_method = 1; } $purchase->save(); } // Push to PayPal IPN of DK $ipn_data = array('plan_id' => $plan_id, 'product_id' => $product_id, 'email' => $buyer->email, 'first_name' => $buyer->first_name, 'last_name' => $buyer->last_name, 'password' => $password, 'transaction_id' => $pay_id ? $pay_id : 'MNL-' . time(), 'amount' => $amount, 'manual_transaction' => TRUE); if ($password) { $ipn_data['dk_new_user'] = TRUE; } else { $ipn_data['dk_new_charge'] = TRUE; $ipn_data['buyer_id'] = $buyer->id; } // Add Curl library require_once app_path() . "/libraries/Curl/Curl.php"; // Post data to IPN $curl = new Curl(); $curl->simple_post($ipn_url, $ipn_data, array(CURLOPT_BUFFERSIZE => 10)); } } } return TRUE; }
public function checkoutAction() { //check if there is a logged in user if (!$this->session->get("auth")) { $this->flash->notice('Please login first'); $this->response->redirect('Session'); } //get logged in user instance and a list of the ids of the products in his cart $user = User::findFirst($this->session->get("auth")['id']); $products_ids = explode(", ", $user->cart); //check if cart is empty if (strlen($user->cart) < 1) { $this->response->redirect("Index"); return $this->flash->notice("Cart is empty!"); } //check if someone bought an item he already had in his cart foreach ($products_ids as $id) { $temp = Product::findFirst($id); if ($temp->stock <= 0) { $this->flash->notice("Error, please re-add items to your cart!"); $user->cart = ''; $user->save(); return $this->response->redirect("Index"); } } $products = array(); $purchase = new Purchase(); $purchase->user_id = $user->id; $purchase->time = new Phalcon\Db\RawValue('now()'); //decrement each product's stock, and add purchase record data foreach ($products_ids as $id) { $temp = Product::findFirst($id); //added more items to cart than in stock, so only purchase available ones if ($temp->stock <= 0) { $this->flash->notice("Error, some items in your cart were not successfully purchased, please check your history"); $user->cart = ''; $user->save(); $purchase->save(); return $this->response->redirect("Index"); } $temp->stock--; $temp->save(); if (strlen($purchase->products) == 0 or is_null($purchase->products)) { $purchase->products = $id; } else { $purchase->products = $purchase->products . ', ' . $id; } $purchase->price += $temp->price; } //check if there is an error with saving the record if (!$purchase->save()) { foreach ($purchase->getMessages() as $message) { $this->flash->error($message); } } else { //empty cart and save $user->cart = ''; $user->save(); } $this->response->redirect("Index"); $this->flash->success("Checkout successful!"); }
/** * Process payment using Stripe * * @return Void */ public function postStripe() { // Add third party libraries require_once app_path() . "/libraries/Curl/Curl.php"; // Add Curl library require_once app_path() . "/libraries/stripe-php-1.9.0/lib/Stripe.php"; // Add Stripe library require_once app_path() . "/libraries/infusionsoft/isdk.php"; // Add InfusionSoft Library // Get Affiliate ID from Cookie $affiliate_id = Cookie::get('_dks_isa'); // Get Product and Plan Data $product = Input::get("product"); $plan = Input::get("plan"); $email = Input::get("email"); $first_name = Input::get("first_name"); $last_name = Input::get("last_name"); $password = Input::get("password"); $ccNum = Input::get('ccNum'); $ccExpire = Input::get('ccExpire'); $ccCSV = Input::get('ccCSV'); $is_split_pay = Input::get("pay_option") == "split" ? TRUE : FALSE; $existing_customer = Input::get('existing_customer'); // Put every detail in Flash session to show again, // if an error occurs Session::flash('email', $email); Session::flash('first_name', $first_name); Session::flash('last_name', $last_name); Session::flash('password', $password); Session::flash('ccNum', $ccNum); Session::flash('ccExpire', $ccExpire); Session::flash('ccCSV', $ccCSV); // Get product data if (!($product = Product::where('code', '=', $product)->first())) { // Invalid product, Redirect to website Session::flash('error', "Product was not found"); return json_encode(array("error" => true, "message" => "Product was not found")); } // Get plan data if (!($plan = Plan::where('code', '=', $plan)->where('product_id', '=', $product->id)->first())) { // Invalid plan, Redirect to website Session::flash('error', "Plan was not found"); return json_encode(array("error" => true, "message" => "Plan was not found")); } // 0. Check if user entered valid email address and password $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'password' => 'required|min:6', 'retype_password' => 'required|same:password', 'ccNum' => 'required', 'ccExpire' => 'required', 'ccCSV' => 'required'); if ($existing_customer) { unset($rules['password']); unset($rules['retype_password']); } $custom_messages = array('ccNum.required' => 'Credit Card number is required', 'ccExpire.required' => 'Credit Card expiry date is required', 'ccCSV.required' => 'Credit Card CSV number is required'); $validator = Validator::make(Input::all(), $rules, $custom_messages); if ($validator->fails()) { $messages = $validator->messages(); $messages_txt = ''; foreach ($messages->all() as $message) { $messages_txt .= "<p>{$message}</p>"; } // Error Session::flash('error', $messages_txt); return json_encode(array("error" => true, "message" => $messages_txt)); } // 1. Check if email already exists in app (Nm etc) DB // Yes, Error - Stop further process if (!$existing_customer) { $curl = new Curl(); $api_url = $product->api_url . "?email={$email}"; $reponse = json_decode($curl->simple_get($api_url)); if (!empty($reponse->user_exists) and $reponse->user_exists == true) { // Error Session::flash('error', "User with this email already exists"); return json_encode(array("error" => true, "message" => "User with this email already exists")); } } // 2. Charge Stripe Card // Error - Stop Stripe::setApiKey(Config::get('project.stripe_secret_key')); $ccExpire = explode("/", $ccExpire); $card = array("number" => $ccNum, "exp_month" => !empty($ccExpire[0]) ? trim($ccExpire[0]) : NULL, "exp_year" => !empty($ccExpire[1]) ? trim($ccExpire[1]) : NULL, "cvc" => $ccCSV); $affiliate_id = Cookie::get('_dks_isa'); $data = array("description" => "{$product->name} - {$plan->name}", "card" => $card, "email" => $email, "metadata" => array("email" => $email, "first_name" => $first_name, "last_name" => $last_name, "password" => $password, "affiliate_id" => $affiliate_id, "product_id" => $product->id, "plan_id" => $plan->id)); // If plan is recurring if ($plan->is_recurring) { $data['plan'] = $plan->stripe_id; $data['account_balance'] = $plan->setup_fee * 100; } // If plan is split payment if ($is_split_pay) { $data['plan'] = $plan->stripe_id . "_split"; $data['account_balance'] = $plan->setup_fee * 100; } try { $customer = Stripe_Customer::create($data); // If plan is not recurring if (!$plan->is_recurring and !$is_split_pay) { Stripe_Charge::create(array("amount" => $plan->price * 100, "currency" => "usd", "customer" => $customer->id, "description" => "Charge for {$plan->name} ({$email})", "metadata" => array("plan_id" => $plan->id))); } } catch (Stripe_Error $e) { // Error Session::flash('error', $e->getMessage()); return json_encode(array("error" => true, "message" => $e->getMessage())); } catch (Exception $e) { // Something else happened, completely unrelated to Stripe Session::flash('error', $e->getMessage()); return json_encode(array("error" => true, "message" => $e->getMessage())); } // No error happened, and we charged user card // Create Buyer Account $buyer = Buyer::where('email', '=', $email)->first(); // Add new buyer in DK System if (!$buyer) { $buyer = new Buyer(); $buyer->email = $email; $buyer->first_name = $first_name; $buyer->last_name = $last_name; $buyer->affiliate_id = $affiliate_id; $buyer->save(); // Add user into Aweber account $this->_add_to_aweber($buyer, $product->aweber_list_id); } else { if ($affiliate_id and $affiliate_id != $buyer->affiliate_id) { // Update new Affiliate ID $buyer->affiliate_id = $affiliate_id; $buyer->save(); } elseif (!$affiliate_id) { $affiliate_id = $buyer->affiliate_id; } } // Update Buyer IP Buyer::updateLastIP($buyer); // Create Purchase in DB $purchase = new Purchase(); $purchase->buyer_id = $buyer->id; $purchase->product_id = $product->id; $purchase->plan_id = $plan->id; $purchase->stripe_token = $customer->id; $purchase->pay_method = 1; $purchase->affiliate_id = $affiliate_id; // If plan is recurring // if($plan->is_recurring) // { // $purchase->stripe_sub_token = $customer->id; // } $purchase->save(); // Everything is ok, now remove session data // for security purpose Session::flash('ccNum', NULL); Session::flash('ccExpire', NULL); Session::flash('ccCSV', NULL); // Create a cookie with email // Cookie Name should have product code $cookieName = "_" . $product->code . "_email"; $cookie = Cookie::forever($cookieName, $email); // ->withCookie($cookie) return Response::make(json_encode(array("success" => true)))->withCookie($cookie); //return json_encode(array("success"=>true)); // 3. Check if email exists in InfusionSoft // Yes - Get contactId // No - Create new contact and get contactId // 4. Create Blank Invoice in InfusionSoft // 5. Add selected productId (InfusionSoft), order item // 6. Get affiliate ID from cookies // If Cookie not exists - Get old affiliate ID from DB // 7. Add manual amount with affiliate id (if exists) // 8. Check if buyer email exists in DK DB // Yes - update affiliate ID // No - Add user in DB with Affiliate ID // 9. Record purchase and transaction with Stripe token ($customer->id) // and Infusion Invoice ID ($newOrder) // 10. Ping product IPN URL with this new purchase }
function updates () { global $Ecart; // Cancel processing if this is not a PayPal Website Payments Standard/Express Checkout IPN if (isset($_POST['txn_type']) && $_POST['txn_type'] != "cart") return false; $target = false; if (isset($_POST['txn_id']) && !isset($_POST['parent_txn_id'])) $target = $_POST['txn_id']; elseif (!empty($_POST['parent_txn_id'])) $target = $_POST['parent_txn_id']; // No transaction target: invalid IPN, silently ignore the message if (!$target) return; // Validate the order notification if ($this->verifyipn() != "VERIFIED") { new EcartError(sprintf(__('An unverifiable order update notification was received from PayPal for transaction: %s. Possible fraudulent notification! The order will not be updated. IPN message: %s','Ecart'),$target,_object_r($_POST)),'paypal_txn_verification',ECART_TRXN_ERR); return false; } $Purchase = new Purchase($target,'txnid'); // Purchase record exists, update it if ($Purchase->txnid == $target && !empty($Purchase->id)) { if ($Purchase->gateway != $this->name) return; // Not a PPS order, don't touch it $txnstatus = isset($this->status[$_POST['payment_status']])? $this->status[$_POST['payment_status']]:$_POST['payment_status']; $Purchase->txnstatus = $txnstatus; $Purchase->save(); $Ecart->Purchase = &$Purchase; $Ecart->Order->purchase = $Purchase->id; do_action('ecart_order_notifications'); die('PayPal IPN update processed.'); } if (!isset($_POST['custom'])) { new EcartError(sprintf(__('No reference to the pending order was available in the PayPal IPN message. Purchase creation failed for transaction %s.'),$target),'paypalstandard_process_neworder',ECART_TRXN_ERR); die('PayPal IPN failed.'); } $Ecart->Order->unhook(); $Ecart->resession($_POST['custom']); $Ecart->Order = Ecart_buyObject::__new('Order',$Ecart->Order); $this->actions(); $Shopping = &$Ecart->Shopping; // Couldn't load the session data if ($Shopping->session != $_POST['custom']) return new EcartError("Session could not be loaded: {$_POST['custom']}",false,ECART_DEBUG_ERR); else new EcartError("PayPal successfully loaded session: {$_POST['custom']}",false,ECART_DEBUG_ERR); $this->ipnupdates(); do_action('ecart_process_order'); // New order die('PayPal IPN processed.'); }
function updates () { global $Ecart; // Cancel processing if this is not a PayPal Website Payments Standard/Express Checkout IPN if (isset($_POST['txn_type']) && $_POST['txn_type'] != "cart") return false; $target = isset($_POST['parent_txn_id'])?$_POST['parent_txn_id']:$_POST['txn_id']; $Purchase = new Purchase($target,'txnid'); if ($Purchase->txn != $target || empty($Purchase->id)) return; // No Purchase found to update if ($Purchase->gateway != $this->module) return; // Not a PPE order, don't touch it // Validate the order notification if ($this->verifyipn() != "VERIFIED") { new EcartError(sprintf(__('An unverifiable order update notification was received from PayPal for transaction: %s. Possible fraudulent notification! The order will not be updated. IPN message: %s','Ecart'),$target,_object_r($_POST)),'paypal_txn_verification',ECART_TRXN_ERR); return false; } if (!$txnstatus) $txnstatus = $this->status[$_POST['payment_status']]; $Purchase->txnstatus = $txnstatus; $Purchase->save(); $Ecart->Purchase = &$Purchase; $Ecart->Order->purchase = $Purchase->id; do_action('ecart_order_notifications'); if (ECART_DEBUG) new EcartError('PayPal IPN update processed for transaction: '.$target,false,ECART_DEBUG_ERR); die('PayPal IPN update processed.'); }
public function create_submit() { //Image Upload $users = DB::table('users')->get(); $purchasecheck = DB::table('purchase_request')->count(); if ($purchasecheck != 0) { $purchase = Purchase::orderby('id', 'DESC')->first(); $docs = Document::orderby('id', 'DESC')->first(); $pr_id = $purchase->id + 1; $doc_id = $docs->id + 1; } else { $pr_id = 1; $doc_id = 1; } foreach (Input::file('file') as $file) { $rules = array('file' => 'required|mimes:png,gif,jpeg,jpg|max:900000000000000000000'); $validator = \Validator::make(array('file' => $file), $rules); $destine = public_path() . "/uploads"; if ($validator->passes()) { $ext = $file->guessClientExtension(); // (Based on mime type) $ext = $file->getClientOriginalExtension(); // (Based on filename) $filename = $file->getClientOriginalName(); $archivo = value(function () use($file) { $filename = str_random(10) . '.' . $file->getClientOriginalExtension(); return strtolower($filename); }); $archivo = value(function () use($file) { $date = date('m-d-Y-h-i-s', time()); $filename = $date . "-" . $file->getClientOriginalName(); return strtolower($filename); }); $attach = new Attachments(); $attach->doc_id = $doc_id; $attach->data = $archivo; $attach->save(); $filename = $doc_id . "_" . $attach->id; $file->move($destine, $archivo); $target_folder = $destine; $upload_image = $target_folder . "/" . $archivo; $thumbnail = $target_folder . "/resize" . $archivo; $actual = $target_folder . "/" . $archivo; // THUMBNAIL SIZE list($width, $height) = getimagesize($upload_image); $newwidth = $width; $newheight = $height; while ($newheight > 525) { $newheight = $newheight * 0.8; $newwidth = $newwidth * 0.8; } $source = $upload_image; $ext = strtolower($ext); $thumb = imagecreatetruecolor($newwidth, $newheight); if ($ext == "jpg" || $ext == "jpeg") { $source = imagecreatefromjpeg($upload_image); } elseif ($ext == "png") { $source = imagecreatefrompng($upload_image); } elseif ($ext == "gif") { $source = imagecreatefromgif($upload_image); } else { continue; } // RESIZE imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // MAKE NEW FILES if ($ext == "jpg" || $ext == "jpeg") { imagejpeg($thumb, $thumbnail, 100); } elseif ($ext == "png") { imagepng($thumb, $thumbnail, 9); } elseif ($ext == "gif") { imagegif($thumb, $thumbnail, 100); } else { echo "An invalid image"; } unlink($actual); // FILE RENAMES rename($thumbnail, $actual); } else { $errors = $validator->errors(); Session::put('imgerror', 'Invalid file.'); } } //End Image Upload $purchase = new Purchase(); $document = new Document(); $purchase->projectPurpose = strip_tags(Input::get('projectPurpose')); $purchase->sourceOfFund = strip_tags(Input::get('sourceOfFund')); $purchase->amount = Input::get('amount'); $purchase->office = Input::get('office'); $purchase->requisitioner = Input::get('requisitioner'); if (!Input::get('dateRequested') == '') { $purchase->dateRequested = Input::get('dateRequested'); } $purchase->dateReceived = Input::get('dateReceived'); $purchase->status = 'Active'; $purchase->otherType = Input::get('otherType'); // Get latest control number $cn = Input::get('controlNo'); $checkUniqueControlNo = Purchase::where('controlNo', '=', "{$cn}")->count(); if ($checkUniqueControlNo != 0) { $purchase->controlNo = ''; } else { $purchase->controlNo = Input::get('controlNo'); } if (Input::get('otherType') == 'Pakyaw') { $purchase->projectType = "None"; } else { $purchase->projectType = Input::get('projectType'); } // Set creator id $user_id = Auth::user()->id; $purchase->created_by = $user_id; $purchase_save = $purchase->save(); if ($purchase_save && (Session::get('imgerror') == NULL || !Input::hasfile('file'))) { $document->pr_id = $purchase->id; $document->work_id = Input::get('hide_modeOfProcurement'); $document_save = $document->save(); if ($document_save) { $doc_id = $document->id; $workflow = Workflow::find($document->work_id); $section = Section::where('workflow_id', $document->work_id)->orderBy('section_order_id', 'ASC')->get(); $firstnew = 0; // Set due date; $new_purchase = Purchase::find($purchase->id); $workflow_id = Input::get('hide_modeOfProcurement'); $workflow = Workflow::find($workflow_id); $addToDate = $workflow->totalDays; date_default_timezone_set("Asia/Manila"); $dueDate = date('Y-m-d H:i:s', strtotime("+{$addToDate} days")); $new_purchase->dueDate = $dueDate; $new_purchase->save(); $tasks = Task::where('wf_id', $document->work_id)->orderBy('section_id', 'ASC')->orderBy('order_id', 'ASC')->get(); foreach ($tasks as $task) { $task_details = new TaskDetails(); $task_details->task_id = $task->id; $stringamount = $new_purchase->amount; $stringamount = str_replace(str_split(','), '', $stringamount); $amount = (double) $stringamount; if ($firstnew == 0) { $task_details->status = "New"; } else { $task_details->status = "Pending"; } //Project Type if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT" || $task->taskName == "PRE-BID CONFERENCE") { $task_details->status = "Lock"; if ($new_purchase->projectType == "Goods/Services") { if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") { if ($amount > 2000000) { $task_details->status = "Pending"; } } else { if ($task->taskName == "PRE-BID CONFERENCE") { if ($amount > 1000000) { $task_details->status = "Pending"; } } } } elseif ($new_purchase->projectType == "Infrastructure") { if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") { if ($amount > 5000000) { $task_details->status = "Pending"; } } else { if ($task->taskName == "PRE-BID CONFERENCE") { if ($amount > 1000000) { $task_details->status = "Pending"; } } } } elseif ($new_purchase->projectType == "Consulting Services") { if ($amount > 1000000) { $task_details->status = "Pending"; } } } //End Project Type $firstnew = 1; $task_details->doc_id = $document->id; $task_details->save(); } $users = User::all(); foreach ($users as $user) { $count = new Count(); $count->user_id = $user->id; $count->doc_id = $doc_id; $count->save(); } $pr_id = Session::get('pr_id'); DB::table('attachments')->where('doc_id', $doc_id)->update(array('saved' => 1)); DB::table('attachments')->where('saved', '=', 0)->delete(); Session::forget('doc_id'); if (!Input::hasfile('file')) { Session::forget('imgerror'); } $connected = @fsockopen("www.google.com", 80); //website, port (try 80 or 443) if ($connected) { $sendee = DB::table('users')->where('id', $purchase->requisitioner)->first(); $email = $sendee->email; $fname = $sendee->firstname; $data = ['id' => $purchase->id]; Mail::send('emails.template', $data, function ($message) use($email, $fname) { $message->from('*****@*****.**', 'Procurement Tracking System Tarlac'); $message->to($email, $fname)->subject('Tarlac Procurement Tracking System: New Purchase Request Created'); }); $notice = "Purchase request created successfully. "; } else { $notice = "Purchase request created successfully. Email notice was not sent. "; } // Insert data to reports table $date_received = Input::get('dateReceived'); $date_received = substr($date_received, 0, strrpos($date_received, ' ')); $reports = Reports::whereDate($date_received)->first(); if ($reports == null) { $reports = new Reports(); $reports->date = $date_received; $reports->pRequestCount = 1; } else { $reports->pRequestCount = $reports->pRequestCount + 1; } $reports->save(); //End Reports Session::put('notice', $notice); $office = Office::all(); $users = User::all(); $workflow = Workflow::all(); return Redirect::to('purchaseRequest/view'); Session::put('imgsuccess', 'Files uploaded.'); } else { $message = "Failed to create purchase request."; Session::put('main_error', $message); // Get Other Error Messages $error_projectPurpose = $purchase->validationErrors->first('projectPurpose'); $error_projectType = $purchase->validationErrors->first('projectType'); $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund'); $error_amount = $purchase->validationErrors->first('amount'); $error_office = $purchase->validationErrors->first('office'); $error_requisitioner = $purchase->validationErrors->first('requisitioner'); $error_dateRequested = $purchase->validationErrors->first('dateRequested'); $error_dateReceived = $purchase->validationErrors->first('dateReceived'); $error_controlNo = $purchase->validationErrors->first('controlNo'); // Inserting Error Message To a Session Session::put('error_projectPurpose', $error_projectPurpose); Session::put('error_sourceOfFund', $error_sourceOfFund); Session::put('error_amount', $error_amount); Session::put('error_office', $error_office); Session::put('error_requisitioner', $error_requisitioner); Session::put('error_dateRequested', $error_dateRequested); Session::put('error_dateReceived', $error_dateReceived); Session::put('error_projectType', $error_projectType); Session::put('error_controlNo', $error_controlNo); if ($checkUniqueControlNo != 0) { Session::put('error_controlNo', 'This control no. already exists. Please enter a new one.'); } if (Input::get('hide_modeOfProcurement') == "") { Session::put('m6', 'required'); } Session::put('imgsuccess', 'Files uploaded.'); return Redirect::back()->withInput(); } } else { // Set Main Error $message = "Failed to create purchase request."; Session::put('main_error', $message); if (!Input::hasfile('file')) { Session::forget('imgerror'); } // Get Other Error Messages $error_projectPurpose = $purchase->validationErrors->first('projectPurpose'); $error_projectType = $purchase->validationErrors->first('projectType'); $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund'); $error_amount = $purchase->validationErrors->first('amount'); $error_office = $purchase->validationErrors->first('office'); $error_requisitioner = $purchase->validationErrors->first('requisitioner'); $error_dateRequested = $purchase->validationErrors->first('dateRequested'); $error_dateReceived = $purchase->validationErrors->first('dateReceived'); $error_controlNo = $purchase->validationErrors->first('controlNo'); // Inserting Error Message To a Session Session::put('error_projectPurpose', $error_projectPurpose); Session::put('error_sourceOfFund', $error_sourceOfFund); Session::put('error_amount', $error_amount); Session::put('error_office', $error_office); Session::put('error_requisitioner', $error_requisitioner); Session::put('error_dateRequested', $error_dateRequested); Session::put('error_dateReceived', $error_dateReceived); Session::put('error_projectType', $error_projectType); Session::put('error_controlNo', $error_controlNo); if ($checkUniqueControlNo != 0) { Session::put('error_controlNo', 'This control no. already exists. Please enter a new one.'); } if (Input::get('hide_modeOfProcurement') == "") { Session::put('error_modeOfProcurement', 'required'); } if (Session::get('imgerror') && Input::hasfile('file')) { $failedpurchasecount = Purchase::where('id', $purchase->id)->count(); if ($failedpurchasecount != 0) { $failedpurchase = Purchase::find($purchase->id); $failedpurchase->delete(); } Session::forget('imgsuccess'); //Image Error Return $task_details = TaskDetails::where('doc_id', $document->id)->delete(); $document->delete(); $message = "Failed to create purchase request."; // Set Main Error $message = "Failed to save purchase request."; Session::put('main_error', $message); // Get Other Error Messages $error_projectPurpose = $purchase->validationErrors->first('projectPurpose'); $error_projectType = $purchase->validationErrors->first('projectType'); $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund'); $error_amount = $purchase->validationErrors->first('amount'); $error_office = $purchase->validationErrors->first('office'); $error_requisitioner = $purchase->validationErrors->first('requisitioner'); $error_dateRequested = $purchase->validationErrors->first('dateRequested'); $error_dateReceived = $purchase->validationErrors->first('dateReceived'); $error_controlNo = $purchase->validationErrors->first('controlNo'); // Inserting Error Message To a Session Session::put('error_projectPurpose', $error_projectPurpose); Session::put('error_sourceOfFund', $error_sourceOfFund); Session::put('error_amount', $error_amount); Session::put('error_office', $error_office); Session::put('error_requisitioner', $error_requisitioner); Session::put('error_dateRequested', $error_dateRequested); Session::put('error_dateReceived', $error_dateReceived); Session::put('error_projectType', $error_projectType); Session::put('error_controlNo', $error_controlNo); if ($checkUniqueControlNo != 0) { Session::put('error_controlNo', 'This control no. already exists. Please enter a new one.'); } } return Redirect::back()->withInput(); } }
/** * refund * * Currently only sets the transaction status to refunded * * @since 1.1 * * @param string $XML The XML request from google * @return void **/ function refund($XML) { $summary = $XML->tag('order-summary'); $id = $summary->content('google-order-number'); $refund = $summary->content('total-refund-amount'); if (empty($id)) { new EcartError("No transaction ID was provided with an order refund notification sent by Google Checkout",'google_refund_notification_error',ECART_DEBUG_ERR); $this->error(); } $Purchase = new Purchase($id,'txnid'); if ( empty($Purchase->id) ) { new EcartError('Transaction refund on non-existing order.','google_refund_missing_order',ECART_DEBUG_ERR); return; } $Purchase->txnstatus = "REFUNDED"; $Purchase->save(); }
function process() { global $Shopp; if (!isset($Shopp->Cart->data->PayPalExpress->token) && !isset($Shopp->Cart->data->PayPalExpress->payerid)) { return false; } $_ = $this->headers(); $_['METHOD'] = "DoExpressCheckoutPayment"; $_['PAYMENTACTION'] = "Sale"; $_['TOKEN'] = $Shopp->Cart->data->PayPalExpress->token; $_['PAYERID'] = $Shopp->Cart->data->PayPalExpress->payerid; // Transaction $_ = array_merge($_, $this->purchase()); $this->transaction = $this->encode($_); $result = $this->send(); if (!$result) { new ShoppError(__('No response was received from PayPal. The order cannot be processed.', 'Shopp'), 'paypalexpress_noresults', SHOPP_COMM_ERR); } if (!$Shopp->Cart->validorder()) { new ShoppError(__('There is not enough customer information to process the order.', 'Shopp'), 'invalid_order', SHOPP_TRXN_ERR); return false; } // If the transaction is a success, get the transaction details, // build the purchase receipt, save it and return it if (strtolower($result->ack) == "success") { $_ = $this->headers(); $_['METHOD'] = "GetTransactionDetails"; $_['TRANSACTIONID'] = $this->Response->transactionid; $this->transaction = $this->encode($_); $result = $this->send(); if (!$result) { new ShoppError(__('Details for the order were not provided by PayPal.', 'Shopp'), 'paypalexpress_notrxn_details', SHOPP_COMM_ERR); return false; } $Order = $Shopp->Cart->data->Order; $Order->Totals = $Shopp->Cart->data->Totals; $Order->Items = $Shopp->Cart->contents; $Order->Cart = $Shopp->Cart->session; $authentication = $Shopp->Settings->get('account_system'); if ($authentication == "wordpress") { // Check if they've logged in // If the shopper is already logged-in, save their updated customer info if ($Shopp->Cart->data->login) { if (SHOPP_DEBUG) { new ShoppError('Customer logged in, linking Shopp customer account to existing WordPress account.', false, SHOPP_DEBUG_ERR); } get_currentuserinfo(); global $user_ID; $Order->Customer->wpuser = $user_ID; } // Create WordPress account (if necessary) if (!$Order->Customer->wpuser) { if (SHOPP_DEBUG) { new ShoppError('Creating a new WordPress account for this customer.', false, SHOPP_DEBUG_ERR); } if (!$Order->Customer->new_wpuser()) { new ShoppError(__('Account creation failed on order for customer id:' . $Order->Customer->id, "Shopp"), false, SHOPP_TRXN_ERR); } } } // Create a WP-compatible password hash to go in the db if (empty($Order->Customer->id)) { $Order->Customer->password = wp_hash_password($Order->Customer->password); } $Order->Customer->save(); $Order->Billing->customer = $Order->Customer->id; $Order->Billing->cardtype = "PayPal"; $Order->Billing->save(); $Order->Shipping->customer = $Order->Customer->id; $Order->Shipping->save(); $Purchase = new Purchase(); $Purchase->customer = $Order->Customer->id; $Purchase->billing = $Order->Billing->id; $Purchase->shipping = $Order->Shipping->id; $Purchase->copydata($Order->Customer); $Purchase->copydata($Order->Billing); $Purchase->copydata($Order->Shipping, 'ship'); $Purchase->copydata($Order->Totals); $Purchase->freight = $Order->Totals->shipping; $Purchase->gateway = "PayPal Express"; $Purchase->transactionid = $this->Response->transactionid; $Purchase->transtatus = $this->status[$this->Response->paymentstatus]; $Purchase->ip = $Shopp->Cart->ip; $Purchase->fees = $this->Response->feeamt; $Purchase->save(); foreach ($Shopp->Cart->contents as $Item) { $Purchased = new Purchased(); $Purchased->copydata($Item); $Purchased->purchase = $Purchase->id; if (!empty($Purchased->download)) { $Purchased->keygen(); } $Purchased->save(); if ($Item->inventory) { $Item->unstock(); } } return $Purchase; } // Fail by default return false; }
public function janisawesome() { function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString; } function generateRandomAmount() { $length = rand(4, 8); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= rand(1, 9); } return $randomString; } $numLoop = 1; while ($numLoop < 301) { $purchase = new Purchase(); $document = new Document(); $purchase->projectPurpose = generateRandomString(); $purchase->sourceOfFund = generateRandomString(); $controlAmt = generateRandomAmount(); $controlAmt .= ".00"; $purchase->amount = number_format($controlAmt); $purchase->office = "1"; $purchase->requisitioner = "1"; $purchase->dateRequested = date('Y-m-d H:i:s'); $purchase->dateReceived = date('Y-m-d H:i:s'); $purchase->status = 'Active'; $purchase->otherType = " "; // Get latest control number $cn = 0; $purchase_controlNo = Purchase::orderBy('ControlNo', 'DESC')->first(); if (!$purchase_controlNo == NuLL) { $cn = $purchase_controlNo->controlNo; } $cn += 1; $purchase->controlNo = $cn; if (Input::get('otherType') == ' ') { $purchase->projectType = "None"; } else { $purchase->projectType = "None"; } // Set creator id $user_id = Auth::user()->id; $purchase->created_by = $user_id; $purchase_save = $purchase->save(); if ($purchase_save) { if ($controlAmt < 50000) { $amtControl = 1; } else { if ($controlAmt >= 50000 && $controlAmt <= 500000) { $amtControl = 2; } else { if ($controlAmt >= 500000) { $amtControl = 3; } } } $document->pr_id = $purchase->id; $document->work_id = $amtControl; $document_save = $document->save(); if ($document_save) { $doc_id = $document->id; $workflow = Workflow::find($document->work_id); $section = Section::where('workflow_id', $document->work_id)->orderBy('section_order_id', 'ASC')->get(); $firstnew = 0; // Set due date; $new_purchase = Purchase::find($purchase->id); $workflow_id = "1"; $workflow = Workflow::find($workflow_id); $addToDate = $workflow->totalDays; date_default_timezone_set("Asia/Manila"); $dueDate = date('Y-m-d H:i:s', strtotime("+{$addToDate} days")); $new_purchase->dueDate = $dueDate; $new_purchase->save(); $tasks = Task::where('wf_id', $document->work_id)->orderBy('section_id', 'ASC')->orderBy('order_id', 'ASC')->get(); foreach ($tasks as $task) { $task_details = new TaskDetails(); $task_details->task_id = $task->id; $stringamount = $new_purchase->amount; $stringamount = str_replace(str_split(','), '', $stringamount); $amount = (double) $stringamount; if ($firstnew == 0) { $task_details->status = "New"; } else { $task_details->status = "Pending"; } //Project Type if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT" || $task->taskName == "PRE-BID CONFERENCE") { $task_details->status = "Lock"; if ($new_purchase->projectType == "Goods/Services") { if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") { if ($amount > 2000000) { $task_details->status = "Pending"; } } else { if ($task->taskName == "PRE-BID CONFERENCE") { if ($amount > 1000000) { $task_details->status = "Pending"; } } } } elseif ($new_purchase->projectType == "Infrastructure") { if ($task->taskName == "PRE-PROCUREMENT CONFERENCE" || $task->taskName == "ADVERTISEMENT") { if ($amount > 5000000) { $task_details->status = "Pending"; } } else { if ($task->taskName == "PRE-BID CONFERENCE") { if ($amount > 1000000) { $task_details->status = "Pending"; } } } } elseif ($new_purchase->projectType == "Consulting Services") { if ($amount > 1000000) { $task_details->status = "Pending"; } } } //End Project Type $firstnew = 1; $task_details->doc_id = $document->id; $task_details->save(); } $users = User::all(); foreach ($users as $user) { $count = new Count(); $count->user_id = $user->id; $count->doc_id = $doc_id; $count->save(); } $pr_id = Session::get('pr_id'); DB::table('attachments')->where('doc_id', $doc_id)->update(array('saved' => 1)); DB::table('attachments')->where('saved', '=', 0)->delete(); Session::forget('doc_id'); $connected = true; // $connected = @fsockopen("www.google.com", 80); //website, port (try 80 or 443) if (!$connected) { $sendee = DB::table('users')->where('id', $purchase->requisitioner)->first(); $email = $sendee->email; $fname = $sendee->firstname; $data = ['id' => $purchase->id]; Mail::send('emails.template', $data, function ($message) use($email, $fname) { $message->from('*****@*****.**', 'Procurement Tracking System Tarlac'); $message->to($email, $fname)->subject('Tarlac Procurement Tracking System: New Purchase Request Created'); }); $notice = "Purchase request created successfully. "; // Insert data to reports table $date_received = Input::get('dateReceived'); $date_received = substr($date_received, 0, strrpos($date_received, ' ')); $reports = Reports::whereDate($date_received)->first(); if ($reports == null) { $reports = new Reports(); $reports->date = $date_received; $reports->pRequestCount = 1; } else { $reports->pRequestCount = $reports->pRequestCount + 1; } $reports->save(); //End Reports } else { // Insert data to reports table $date_received = Input::get('dateReceived'); $date_received = substr($date_received, 0, strrpos($date_received, ' ')); $reports = Reports::whereDate($date_received)->first(); if ($reports == null) { $reports = new Reports(); $reports->date = $date_received; $reports->pRequestCount = 1; } else { $reports->pRequestCount = $reports->pRequestCount + 1; } $reports->save(); //End Reports $notice = "Purchase request created successfully. Email notice was not sent. "; } Session::put('notice', $notice); $office = Office::all(); $users = User::all(); $workflow = Workflow::all(); //return Redirect::to('purchaseRequest/view'); return Redirect::to('janisawesome'); Session::put('imgsuccess', 'Files uploaded.'); } else { $message = "Failed to create purchase request."; Session::put('main_error', $message); // Get Other Error Messages $error_projectPurpose = $purchase->validationErrors->first('projectPurpose'); $error_projectType = $purchase->validationErrors->first('projectType'); $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund'); $error_amount = $purchase->validationErrors->first('amount'); $error_office = $purchase->validationErrors->first('office'); $error_requisitioner = $purchase->validationErrors->first('requisitioner'); $error_dateRequested = $purchase->validationErrors->first('dateRequested'); $error_dateReceived = $purchase->validationErrors->first('dateReceived'); // Inserting Error Message To a Session Session::put('error_projectPurpose', $error_projectPurpose); Session::put('error_sourceOfFund', $error_sourceOfFund); Session::put('error_amount', $error_amount); Session::put('error_office', $error_office); Session::put('error_requisitioner', $error_requisitioner); Session::put('error_dateRequested', $error_dateRequested); Session::put('error_dateReceived', $error_dateReceived); Session::put('error_projectType', $error_projectType); if (Input::get('hide_modeOfProcurement') == "") { Session::put('m6', 'required'); } Session::put('imgsuccess', 'Files uploaded.'); return Redirect::back()->withInput(); } } else { // Set Main Error $message = "Failed to create purchase request."; Session::put('main_error', $message); // Get Other Error Messages $error_projectPurpose = $purchase->validationErrors->first('projectPurpose'); $error_projectType = $purchase->validationErrors->first('projectType'); $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund'); $error_amount = $purchase->validationErrors->first('amount'); $error_office = $purchase->validationErrors->first('office'); $error_requisitioner = $purchase->validationErrors->first('requisitioner'); $error_dateRequested = $purchase->validationErrors->first('dateRequested'); $error_dateReceived = $purchase->validationErrors->first('dateReceived'); // Inserting Error Message To a Session Session::put('error_projectPurpose', $error_projectPurpose); Session::put('error_sourceOfFund', $error_sourceOfFund); Session::put('error_amount', $error_amount); Session::put('error_office', $error_office); Session::put('error_requisitioner', $error_requisitioner); Session::put('error_dateRequested', $error_dateRequested); Session::put('error_dateReceived', $error_dateReceived); Session::put('error_projectType', $error_projectType); if (Input::get('hide_modeOfProcurement') == "") { Session::put('error_modeOfProcurement', 'required'); } if (Session::get('imgerror') && Input::hasfile('file')) { $failedpurchasecount = Purchase::where('id', $purchase->id)->count(); if ($failedpurchasecount != 0) { $failedpurchase = Purchase::find($purchase->id); $failedpurchase->delete(); } Session::forget('imgsuccess'); //Image Error Return $task_details = TaskDetails::where('doc_id', $document->id)->delete(); $document->delete(); $message = "Failed to create purchase request."; // Set Main Error $message = "Failed to save purchase request."; Session::put('main_error', $message); // Get Other Error Messages $error_projectPurpose = $purchase->validationErrors->first('projectPurpose'); $error_projectType = $purchase->validationErrors->first('projectType'); $error_sourceOfFund = $purchase->validationErrors->first('sourceOfFund'); $error_amount = $purchase->validationErrors->first('amount'); $error_office = $purchase->validationErrors->first('office'); $error_requisitioner = $purchase->validationErrors->first('requisitioner'); $error_dateRequested = $purchase->validationErrors->first('dateRequested'); $error_dateReceived = $purchase->validationErrors->first('dateReceived'); // Inserting Error Message To a Session Session::put('error_projectPurpose', $error_projectPurpose); Session::put('error_sourceOfFund', $error_sourceOfFund); Session::put('error_amount', $error_amount); Session::put('error_office', $error_office); Session::put('error_requisitioner', $error_requisitioner); Session::put('error_dateRequested', $error_dateRequested); Session::put('error_dateReceived', $error_dateReceived); Session::put('error_projectType', $error_projectType); } return Redirect::back()->withInput(); } $numLoop++; } }
/** * Sets transaction information to create the purchase record * * @since 1.1 * * @param string $id Transaction ID * @param string $status (optional) Transaction status (PENDING, CHARGED, VOID, etc) * @param float $fees (optional) Transaction fees assesed by the processor * * @return true **/ function transaction ($id,$status="PENDING",$fees=0) { $this->txnid = $id; $this->txnstatus = $status; $this->fees = $fees; if (empty($this->txnid)) return new EcartError(sprintf('The payment gateway %s did not provide a transaction id. Purchase records cannot be created without a transaction id.',$this->gateway),'ecart_order_transaction',ECART_DEBUG_ERR); $Purchase = new Purchase($this->txnid,'txnid'); if (!empty($Purchase->id)) $Purchase->save(); else do_action('ecart_create_purchase'); return true; }
function state($XML) { $id = $XML->getElementContent('google-order-number'); $state = $XML->getElementContent('new-financial-order-state'); $Purchase = new Purchase($id, 'transactionid'); $Purchase->transtatus = $state; $Purchase->save(); if (strtoupper($state) == "CHARGEABLE" && $this->settings['autocharge'] == "on") { $_ = array('<?xml version="1.0" encoding="utf-8"?>' . "\n"); $_[] = '<charge-order xmlns="' . $this->urls['schema'] . '" google-order-number="' . $id . '">'; $_[] = '<amount currency="' . $this->settings['currency'] . '">' . $Purchase->total . '</amount>'; $_[] = '</charge-order>'; $this->transaction = join("\n", $_); $Reponse = $this->send($this->urls['order']); exit; } }
public function executeGeneratePurchase(sfWebRequest $request) { $invoice = Doctrine_Query::create()->from('Invoice i')->where('i.id = ' . $request->getParameter('id'))->fetchOne(); //create purchase $purchase = new Purchase(); $purchase->setDate(date("Y-m-d")); $purchase->setPono(date('h:i:s a')); $purchase->save(); //create purchase details foreach ($invoice->getInvoicedetail() as $invdetail) { $purchdetail = new PurchaseDetail(); $purchdetail->setPurchaseId($purchase->getId()); $purchdetail->setProductId($invdetail->getProductId()); $purchdetail->setDescription($invdetail->getProduct()->getName()); $purchdetail->setQty($invdetail->getQty()); $purchdetail->setPrice(0); $purchdetail->setTotal(0); $purchdetail->setUnittotal(0); $purchdetail->save(); $purchdetail->updateStockentry(); } $this->redirect("purchase/view?id=" . $purchase->getId()); }
function updates() { if (!isset($_POST['parent_txn_id'])) { return false; } // Not a notification request $Purchase = new Purchase($_POST['parent_txn_id'], 'transactionid'); if (empty($Purchase->id)) { return false; } // No order exists, bail out if (!$txnstatus) { $txnstatus = $this->status[$_POST['payment_status']]; } // Order exists, handle IPN updates $Purchase->transtatus = $txnstatus; $Purchase->save(); }