codigo actual del servidor, con avances de joan

This commit is contained in:
Jose Sanchez
2023-08-07 15:52:04 -04:00
commit 3cd9b8bbe8
3070 changed files with 532255 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class AttributeValueRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'attribute_id' => 'required',
'value' => ['required', 'max:255', Rule::unique('attribute_values')->ignore($this->attribute_value)],
'color_code' => ['required_if:type,color','max:255', Rule::unique('attribute_values')->ignore($this->attribute_value)],
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'attribute_id.required' => translate('Attribute is required'),
'value.required' => translate('Attribute value is required'),
'value.max' => translate('Max 255 characters for attribute value'),
'color_code.required_if:type' => translate('Color code is required'),
];
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CarrierRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'carrier_name' => 'required|max:255',
'transit_time' => 'required|max:255',
'delimiter1.*' => 'required',
'delimiter2.*' => 'required',
'carrier_price.*.*' => 'required',
'zones' => 'required_without:shipping_type',
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'carrier_name.required' => translate('Carrier name is required'),
'carrier_name.max' => translate('Max 255 characters'),
'transit_time.required' => translate('Transit time is required'),
'delimiter1.*.required' => translate('Delimiter1 is required'),
'delimiter2.*.required' => translate('Delimiter2 is required'),
'carrier_price.*.*.required' => translate('Carrier price is required'),
'zones.required' => translate('Zone is required. If zone is not created, then create zone at first'),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CartRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
//
];
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\ValidationException;
class CouponRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$productsRule = 'sometimes';
$minBuyRule = 'sometimes';
$maxDiscountRule = 'sometimes';
if ($this->request->get('type') == 'product_base') {
$productsRule = 'required';
}
if ($this->request->get('type') == 'cart_base') {
$minBuyRule = ['required', 'numeric', 'min:1'];
$maxDiscountRule = ['required', 'numeric', 'min:1'];
}
return [
'type' => ['required'],
'code' => ['required', Rule::unique('coupons')->ignore($this->coupon), 'max:255',],
'discount' => ['required', 'numeric', 'min:1'],
'discount_type' => ['required'],
'product_ids' => $productsRule,
'min_buy' => $minBuyRule,
'max_discount' => $maxDiscountRule,
'date_range' => ['required'],
'start_date' => ['required'],
'end_date' => ['required'],
'details' => ['required'],
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'type.required' => translate('Coupon type is required'),
'code.required' => translate('Coupon code is required'),
'code.unique' => translate('Coupon already exist for this coupon code'),
'code.max' => translate('Max 255 characters'),
'product_ids.required' => translate('Product is required'),
'discount.required' => translate('Discount is required'),
'discount.numeric' => translate('Discount should be numeric type'),
'discount.min' => translate('Discount should be l or greater'),
'discount_type.required' => translate('Discount type is required'),
'min_buy.required' => translate('Minimum shopping amount is required'),
'min_buy.numeric' => translate('Minimum shopping amount should be numeric type'),
'min_buy.min' => translate('Minimum shopping amount should be l or greater'),
'max_discount.required' => translate('Max discount amount is required'),
'max_discount.numeric' => translate('Max discount amount should be numeric type'),
'max_discount.min' => translate('Max discount amount should be l or greater'),
'date_range.required' => translate('Date Range is required'),
];
}
protected function prepareForValidation()
{
$date_range = explode(" - ", $this->date_range);
$start_date = '';
$end_date = '';
// dd($date_range);
if($date_range[0]) {
$start_date = strtotime($date_range[0]);
$end_date = strtotime($date_range[1]);
}
$coupon_details = null;
if ($this->type == "product_base") {
$coupon_details = array();
if($this->product_ids) {
foreach ($this->product_ids as $product_id) {
$data['product_id'] = $product_id;
array_push($coupon_details, $data);
}
}
$coupon_details = json_encode($coupon_details);
} elseif ($this->type == "cart_base") {
$data = array();
$data['min_buy'] = $this->min_buy;
$data['max_discount'] = $this->max_discount;
$coupon_details = json_encode($data);
}
$this->merge([
'start_date' => $start_date,
'end_date' => $end_date,
'details' => $coupon_details
]);
}
/**
* Get the error messages for the defined validation rules.*
* @return array
*/
public function failedValidation(Validator $validator)
{
// dd($this->expectsJson());
if ($this->expectsJson()) {
throw new HttpResponseException(response()->json([
'message' => $validator->errors()->all(),
'result' => false
], 422));
} else {
throw (new ValidationException($validator))
->errorBag($this->errorBag)
->redirectTo($this->getRedirectUrl());
}
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\ValidationException;
class ProductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [];
$rules['name'] = 'required|max:255';
$rules['category_id'] = 'required';
$rules['unit' ] = 'required';
$rules['min_qty' ] = 'required|numeric';
$rules['unit_price'] = 'required|numeric';
if ($this->get('discount_type') == 'amount') {
$rules['discount' ] = 'required|numeric|lt:unit_price';
}else {
$rules['discount' ] = 'required|numeric|lt:100';
}
$rules['current_stock'] = 'required|numeric';
return $rules;
}
/**
* Get the validation messages of rules that apply to the request.
*
* @return array
*/
public function messages()
{
return [
'name.required' => 'Product name is required',
'category_id.required' => 'Category is required',
'unit.required' => 'Unit field is required',
'min_qty.required' => 'Minimum purchase quantity is required',
'min_qty.numeric' => 'Minimum purchase must be numeric',
'unit_price.required' => 'Unit price is required',
'unit_price.numeric' => 'Unit price must be numeric',
'discount.required' => 'Discount is required',
'discount.numeric' => 'Discount must be numeric',
'discount.lt:unit_price' => 'Discount can not be gretaer than unit price',
'current_stock.required' => 'Current stock is required',
'current_stock.numeric' => 'Current stock must be numeric',
];
}
/**
* Get the error messages for the defined validation rules.*
* @return array
*/
public function failedValidation(Validator $validator)
{
// dd($this->expectsJson());
if ($this->expectsJson()) {
throw new HttpResponseException(response()->json([
'message' => $validator->errors()->all(),
'result' => false
], 422));
} else {
throw (new ValidationException($validator))
->errorBag($this->errorBag)
->redirectTo($this->getRedirectUrl());
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SellerProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$newPasswordRule = 'sometimes';
$confirmPasswordRule = 'sometimes';
if ($this->request->get('new_password') != null && $this->request->get('confirm_password') != null) {
$newPasswordRule = ['min:6'];
$newPasswordRule = ['min:6'];
}
return [
'name' => ['required', 'max:191'],
'new_password' => $newPasswordRule,
'confirm_password' => $confirmPasswordRule,
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'name.required' => translate('Name is required'),
'new_password.min' => translate('Minimum 6 characters'),
'confirm_password.min' => translate('Minimum 6 characters'),
];
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\ValidationException;
class SellerRegistrationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
$rules = [];
$rules['name'] = 'required|string|max:255';
$rules['email'] = 'required|email|unique:users|max:255';
$rules['password' ] = 'required|string|min:6'; /* |confirmed */
$rules['shop_name' ] = 'required|max:255';
$rules['address'] = 'required';
return $rules;
}
public function messages()
{
return [
'name.required' => translate('Name is required'),
'name.string' => translate('Name should be string type'),
'name.max' => translate('Max 255 characters'),
'email.required' => translate('Email is required'),
'email.email' => translate('Please type a valid email'),
'email.unique' => translate('Email should be unique'),
'email.max' => translate('Max 255 characters'),
'password.required' => translate('Password is required'),
'password.string' => translate('Password should be string type'),
'password.min' => translate('Min 6 characters'),
'password.confirmed' => translate('Confirm password do not matched'),
'shop_name.required' => translate('Shop name is required'),
'shop_name.max' => translate('Max 255 characters'),
'address.required' => translate('Address is required'),
];
}
public function failedValidation(Validator $validator)
{
if ($this->expectsJson()) {
throw new HttpResponseException(response()->json([
'message' => $validator->errors()->all(),
'result' => false
], 422));
} else {
throw (new ValidationException($validator))
->errorBag($this->errorBag)
->redirectTo($this->getRedirectUrl());
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Validation\ValidationException;
use App\Models\User;
use Illuminate\Validation\Rule;
class WholesaleProductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
protected function prepareForValidation(): void
{
$approved = 1;
if (auth()->user()->user_type == 'seller') {
$added_by = 'seller';
$user_id = auth()->user()->id;
if (get_setting('product_approve_by_admin') == 1) {
$approved = 0;
}
} else {
$added_by = 'admin';
$user_id = User::where('user_type', 'admin')->first()->id;
}
$this->merge([
'slug' => ($this->slug == null) ? preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', strtolower($this->name))) : $this->slug,
'user_id' => $user_id,
'approved' => $approved,
'wholesale_product' => 1,
'added_by' => $added_by,
'shipping_cost' => ($this->shipping_type == 'free') ? 0 : $this->flat_shipping_cost,
'published' => ($this->button == 'unpublish') ? 0 : 1,
]);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [];
$rules['name'] = 'required|max:255';
$rules['slug'] = ['required', 'max:255', Rule::unique('products')->ignore($this->id)];
$rules['category_id'] = 'required';
$rules['unit'] = 'required';
$rules['min_qty'] = 'required|numeric';
$rules['unit_price'] = 'required|numeric|gt:0';
$rules['wholesale_min_qty.*'] = 'required';
$rules['wholesale_max_qty.*'] = 'required';
$rules['wholesale_price.*'] = 'required';
$rules['current_stock'] = 'required|numeric';
return $rules;
}
/**
* Get the validation messages of rules that apply to the request.
*
* @return array
*/
public function messages()
{
return [
'name.required' => 'Product name is required',
'category_id.required' => 'Category is required',
'unit.required' => 'Unit field is required',
'min_qty.required' => 'Minimum purchase quantity is required',
'min_qty.numeric' => 'Minimum purchase must be numeric',
'unit_price.required' => 'Unit price is required',
'unit_price.numeric' => 'Unit price must be numeric',
'current_stock.required' => 'Current stock is required',
'current_stock.numeric' => 'Current stock must be numeric',
'wholesale_min_qty.*.required' => 'Product minimum qantity is required',
'wholesale_max_qty.*.required' => 'Product maximum qantity is required',
'wholesale_price.*.required' => 'Product price is required'
];
}
/**
* Get the error messages for the defined validation rules.*
* @return array
*/
public function failedValidation(Validator $validator)
{
// dd($this->expectsJson());
if ($this->expectsJson()) {
throw new HttpResponseException(response()->json([
'message' => $validator->errors()->all(),
'result' => false
], 422));
} else {
throw (new ValidationException($validator))
->errorBag($this->errorBag)
->redirectTo($this->getRedirectUrl());
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ZoneRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => ['required'],
'status' => ['required'],
'country_id' => ['required']
];
}
public function prepareForValidation()
{
$this->merge([
'status' => 1
]);
}
}