first attempt to record client

This commit is contained in:
Kayn Ty 2018-04-10 10:16:23 +02:00
parent cada22694d
commit 013c990540
4 changed files with 136 additions and 10 deletions

View File

@ -56,7 +56,8 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<button class="btn btn-primary btn-block" id="validate_selling" ng-click="sendForm()"> <button class="btn btn-primary btn-block" id="validate_selling" ng-click="sendForm()"
ng-disabled="!paidAmount">
<i class="fa fa-check"></i> <i class="fa fa-check"></i>
Valider Valider
</button> </button>

View File

@ -2,6 +2,8 @@
namespace AppBundle\Controller; namespace AppBundle\Controller;
use AppBundle\Entity\ProductSold;
use AppBundle\Entity\SellRecord;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
@ -120,20 +122,60 @@ class DefaultController extends Controller {
public function addSellingAction( Request $request ) { public function addSellingAction( Request $request ) {
// var_dump( $request->request ); // var_dump( $request->request );
// die(); // die();
$json = json_decode( $request->getContent() ); $json = json_decode( $request->getContent(), true );
// link selling record with user, festival // var_dump( $json );
// die();
$currentUser = $this->getUser();
$m = $this->getDoctrine()->getManager();
$newSellRecord = new SellRecord();
// sort user categories
$myCategories = $m->getRepository( 'AppBundle:ProductCategory' )->findAll();
$categoriesByID = [];
foreach ( $myCategories as $my_category ) {
$categoriesByID[ $my_category->getId() ] = $my_category;
}
$productsModels = $m->getRepository( 'AppBundle:Product' )->findAll();
$productsModelsByID = [];
foreach ( $productsModels as $product ) {
$productsModelsByID[ $product->getId() ] = $product;
}
foreach ( $json[ 'activeSelling' ] as $record ) {
var_dump( $categoriesByID[ $record[ 'category' ] ] );
$newProductSold = new ProductSold();
// $newProductSold->setCategory( $categoriesByID[ $record[ 'category' ] ] );
$newProductSold->setName( $record[ 'name' ] );
$newProductSold->setPrice( $record[ 'price' ] );
$newProductSold->setProduct( $productsModelsByID[ $record[ 'id' ] ] );
$newProductSold->setUser( $currentUser );
$newProductSold->setSellRecords( $newSellRecord );
// link selling record with user, festival
$currentUser->addProductsSold( $newProductSold );
// persist all
$m->persist( $newProductSold );
}
$newSellRecord->setPaidByClient( 0 );
$newSellRecord->setAmount( 42 );
$newSellRecord->setDate( new \DateTime() );
// $newSellRecord->setPaidByClient( $json[ 'paidByClient' ] );
$currentUser->addSellRecords( $newSellRecord );
$m->persist( $newSellRecord );
$m->persist( $currentUser );
$m->flush();
// setup dates // setup dates
// persist all
// fetch back history of selling // fetch back history of selling
// echo "<pre>"; $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
// var_dump( $request->getContent() ); $lastSellings = $sellingRepo->find( [], [ 'id' => 'desc' ], 0, 3 );
//
// echo "</pre>";
// return var_dump( $request->getContent() ); // return var_dump( $request->getContent() );
return new JsonResponse( [ return new JsonResponse( [
"message" => "ok", "message" => "ok",
"recent_sellings" => [], "recent_sellings" => $lastSellings,
"dump" => $json, "dump" => $json,
] ); ] );
} }

View File

@ -10,12 +10,81 @@ use Doctrine\ORM\Mapping as ORM;
class ProductSold extends Product { class ProductSold extends Product {
/** /**
* the stack of products for one client at one time
* @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold") * @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold")
*/ */
private $sellRecords; public $sellRecords;
/** /**
* person who recorded the sell
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold") * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
*/ */
private $user; private $user;
/**
* references the product from whom this line is inspired
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product", inversedBy="productsSold")
*/
private $product;
/**
* @ORM\ManyToOne(targetEntity="ProductCategory", inversedBy="products")
*/
private $category;
/**
* @return mixed
*/
public function getCategory() {
return $this->category;
}
/**
* @param mixed $category
*/
public function setCategory( $category ) {
$this->category = $category;
}
/**
* @return mixed
*/
public function getSellRecords() {
return $this->sellRecords;
}
/**
* @param mixed $sellRecords
*/
public function setSellRecords( $sellRecords ) {
$this->sellRecords = $sellRecords;
}
/**
* @return mixed
*/
public function getUser() {
return $this->user;
}
/**
* @param mixed $user
*/
public function setUser( $user ) {
$this->user = $user;
}
/**
* @return mixed
*/
public function getProduct() {
return $this->product;
}
/**
* @param mixed $product
*/
public function setProduct( $product ) {
$this->product = $product;
}
} }

View File

@ -52,6 +52,13 @@ class User extends BaseUser {
return $this->productsSold; return $this->productsSold;
} }
/**
* @return mixed
*/
public function addProductsSold( $product ) {
return $this->productsSold[] = $product;
}
/** /**
* @param mixed $productsSold * @param mixed $productsSold
*/ */
@ -78,6 +85,13 @@ class User extends BaseUser {
$this->sellRecords = $sellRecords; $this->sellRecords = $sellRecords;
} }
/**
* @param mixed $sellRecords
*/
public function addSellRecords( $sellRecords ) {
$this->sellRecords[] = $sellRecords;
}
/** /**
* @return mixed * @return mixed
*/ */