Describe how to get a specific user in swagger yii2? - yii2

I have a method (show) with which I get information about a specific user. How to describe it in a swagher link (localhost/users/12)?
/**
* #SWG\Get(path="/api/users/id",
* tags={"User"},
* summary="",
* #SWG\Parameter(
* name="Authorization",
* in="header",
* description="",
* required=true,
* type="string"
* ),
* #SWG\Response(
* response = 200,
* description = "Ok",
* #SWG\Schema(ref = "#/")
* ),
* #SWG\Response(
* response = 400,
* description = "Bad Request",
* #SWG\Schema(ref = "#/")
* ),
* #SWG\Response(
* response = 404,
* description = "Not Found",
* #SWG\Schema(ref = "#/")
* ),
* #SWG\Response(
* response = 500,
* description = "Internal Server Error"
* )
* )
*/

/**
* #SWG\Get(path="/api/users/{id}",
* tags={"User"},
* summary="",
* #SWG\Parameter(
* name="Authorization",
* in="header",
* description="",
* required=true,
* type="string"
* ),
* #SWG\Parameter(
* name="id",
* in="path",
* description="Укажите ID",
* required=true,
* type="string"
* ),
* #SWG\Response(
* response = 200,
* description = "Ok",
* #SWG\Schema(ref = "#/")
* ),
* #SWG\Response(
* response = 400,
* description = "Bad Request",
* #SWG\Schema(ref = "#/")
* ),
* #SWG\Response(
* response = 404,
* description = "Not Found",
* #SWG\Schema(ref = "#/")
* ),
* #SWG\Response(
* response = 500,
* description = "Internal Server Error"
* )
* )
*/

Related

Error in WITH RECURSIVE while troubleshooting hacker rank

Summary HackerRank Problem
(1) Draw Triangle 1
P(5) :
* * * * *
* * * *
* * *
* *
*
This is example and i have to make this P(20)
WITH RECURSIVE stars (n,star) AS(
SELECT 39,LEFT('* * * * * * * * * * * * * * * * * * * *',39)
UNION ALL
SELECT n-2,LEFT('* * * * * * * * * * * * * * * * * * * *',n-2)
FROM stars
WHERE n>1
)
SELECT star
FROM stars
I solved question of Draw the Triangle 1 in this way.
(2) Draw Triangle 2
P(5):
*
* *
* * *
* * * *
* * * * *
This is example and i have to make this P(20)
However, this does not work in Draw THE Triangle 2
WITH RECURSIVE stars (n,star) AS(
SELECT 1, LEFT('* * * * * * * * * * * * * * * * * * * *',1)
UNION ALL
SELECT n+2, LEFT('* * * * * * * * * * * * * * * * * * * *',n+2)
FROM stars
WHERE n<38
)
SELECT star
FROM stars
WITH RECURSIVE stars (n,star) AS(
SELECT 1,'*'
UNION ALL
SELECT n+1, CONCAT(star,' *')
FROM stars
WHERE n<20
)
SELECT star
FROM stars
I tried using LEFT() by changing the number just like Triange 1, but the HackerRank site showed a message like 'ERROR 1406 (22001) at line 1: Data too long for column 'star' at row 1' In my personal mysql, I only got OK, but I couldn't see the result table.
If the data is too long and it is an error, shouldn't I meet the same error in the first problem?
Is there something I don't know ?
Take a good look at outputs of queries for "triangle 1" and "triangle 2".
What is the difference? That's right, rows for the "triangle 2" query are in reverse order.
Which value in the query for "triangle 1" defines the order of rows? That's right, it's n.
How can I modify the query for "triangle 1" so that it outputs rows in reverse order? That's right, since the value of n in the first row is 39 and the last one is 1 (the rows are ordered by n in descending order), just reverse rows order by adding ORDER BY n.
So the query for "triangle2" should look like
WITH RECURSIVE stars(n, star) AS(
SELECT 39, LEFT('* * * * * * * * * * * * * * * * * * * *', 39)
UNION ALL
SELECT n-2, LEFT('* * * * * * * * * * * * * * * * * * * *', n-2)
FROM stars
WHERE n > 1
)
SELECT star
FROM stars
ORDER BY n
Just check it

MySql calculate multiple column

I have code below and in my query but the results it gives me is way off chart, so I thought maybe my calculation is wrong. The Logic is to have multiple column sum minus and times to eachother and the result based on my database numbers has to be 4.581.709.50 but I get something like 164.610.000
SUM(c.gaji_pokok + c.uang_makan + c.tunjangan + c.kendaraan + c.overtime + c.komisi + c.lain_lain + c.cuti -
m.pot_absen_hari * m.pot_absen_rate - IFNULL(g.pot_absen_hari * g.pot_absen_rate, 0) - CONCAT((c.uang_makan)/0.25)*0.05 -
n.pot_komisi_dl - n.pot_komisi_p312 - n.pot_komisi_mteg - IFNULL(g.pot_komisi_kasbon, 0) - q.bpjs4 - o.pot_ppn_21pt - o.pot_pinjaman - o.pot_ppn21 - o.pot_bayar_bonus -
o.pot_bayar_thr - c.cuti) as bulan_ppn21,
Query
SELECT
a.nip,
SUM(c.gaji_pokok + c.uang_makan + c.tunjangan + c.kendaraan + c.overtime + c.komisi + c.lain_lain + c.cuti -
m.pot_absen_hari * m.pot_absen_rate - IFNULL(g.pot_absen_hari * g.pot_absen_rate, 0) - CONCAT((c.uang_makan)/0.25)*0.05 -
n.pot_komisi_dl - n.pot_komisi_p312 - n.pot_komisi_mteg - IFNULL(g.pot_komisi_kasbon, 0) - q.bpjs4 - o.pot_ppn_21pt - o.pot_pinjaman - o.pot_ppn21 - o.pot_bayar_bonus -
o.pot_bayar_thr - c.cuti) as bulan_ppn21,
IFNULL((
CASE
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=50000000)
THEN (0.05*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)))
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=250000000)
THEN (0.15*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.15)-(q.jht*12)))
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=500000000)
THEN (0.25*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.25)-(q.jht*12))) end),0) as tahun_pph21,
IFNULL((
CASE
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=50000000)
THEN (0.05*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)))
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=250000000)
THEN (0.15*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.15)-(q.jht*12)))
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=500000000)
THEN (0.25*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.25)-(q.jht*12))) end) -(
CASE
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=50000000)
THEN (0.05*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)))
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=250000000)
THEN (0.15*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.15)-(q.jht*12)))
WHEN ((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)<=500000000)
THEN (0.25*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.25)-(q.jht*12))) end)/12,0) - (
CASE
WHEN (((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))<=50000000)
THEN (0.05*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate)))
WHEN (((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))<=250000000)
THEN (0.15*((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))-5000000)
WHEN (((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))<=500000000)
THEN (0.25*(0.03*(c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))-55000000)*1.2
WHEN (((c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))<=500000000)
THEN (0.25*(0.03*(c.gaji_pokok * 12)-((c.gaji_pokok * 12)*0.05)-(q.jht*12)-(r.pt_kp_rate))-55000000)*1.2 end) as tot_pph21
FROM `t_pegawai` a
LEFT JOIN t_penggajian_karyawan c ON c.nip=a.nip
LEFT JOIN t_departemen d ON d.id_departemen=a.id_departemen
LEFT JOIN t_jabatan e ON e.id_jabatan=a.id_jabatan
LEFT JOIN t_perusahaan f ON f.kode_unitbisnis = a.unit_bisnis
LEFT JOIN absensi k ON k.pin = a.pin
LEFT JOIN t_periode l ON l.nama_periode=c.bulan and YEAR(l.periode_start) = c.tahun
LEFT JOIN t_potongan_absen m ON m.nip=a.nip and m.nip=c.nip and m.bulan = l.id_periode and m.tahun = YEAR(l.periode_start)
LEFT JOIN t_potongan_gaji g ON g.nip=a.nip and g.nip=c.nip and g.bulan = l.id_periode and g.tahun = YEAR(l.periode_start)
LEFT JOIN t_potongan_komisi n ON n.nip=a.nip and n.nip=c.nip and n.bulan = l.id_periode and n.tahun = YEAR(l.periode_start)
LEFT JOIN t_potongan_ppn o ON o.nip=a.nip and o.nip=c.nip and o.bulan = l.id_periode and o.tahun = YEAR(l.periode_start)
LEFT JOIN t_jenjang_bpjs q ON q.nip=a.nip and q.tahun = YEAR(l.periode_start)
LEFT JOIN t_ptkp r ON r.pt_kp_name=a.status_ptkp
WHERE l.id_periode='8' AND f.kode_unitbisnis ='PJS-001' and k.Tanggal >= l.periode_start and k.Tanggal <= l.periode_end
GROUP BY a.pin
Any suggestion on calculation way to make it right?

Perform query on a calculated column using Laravel

I want to perform the following SQL statement in PHP using Laravel's Eloquent model:
SELECT *, (3959 * acos(cos(radians(37)) * cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37)) * sin(radians(lat )))) AS distance
FROM example_retailers
HAVING distance < 1000
ORDER BY distance
OFFSET 4
LIMIT 3;
I am struggling to translate this into a Laravel's Eloquent Model (mainly the calculated column).
This is what I have so far:
ExampleRetailer::
// TODO: add calculated row
where('distance', '<', 100)
->orderBy('distance')
->skip(4)
->limit(3)
->get();
You can use raw queries (source )
DB::table('example_retailers')
->select(DB::raw('*, (3959 * acos(cos(radians(37)) * cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37)) * sin(radians(lat )))) AS distance'))
->having('distance', '<', 100)
->orderBy('distance')
->skip(4)
->limit(3)
->get();
If it's only to make a new row using SQL:
SELECT *, CASE WHEN (3959 * acos(cos(radians(37))
* cos(radians(lat))
* cos(radians(lng) - radians(-122))
+ sin(radians(37))
* sin(radians(lat )))) < 100 THEN END AS NewRow
FROM example_retailers

send dot clicks to server using html5

I am trying to echo user input. Idea is user clicks the dots to draw a shape and then clicks submit. I receive the 'dots' he clicked, and then I reply back the dot numbers. example --
A B C D E F G H I J
1 * * * * * * * * * *
2 * * * * * * * * * *
3 * * * * * * * * * *
4 * * * * * * * * * *
5 * * * * * * * * * *
If a user clicks the '+' ones --
A B C D E F G H I J
1 * * * * * * * * * *
2 * * * * * + * + * *
3 * * * * * + * + * *
4 * * * * * * + * * *
5 * * * * * * * * * *
and then submits the page, I then give him - F2F3G4H3H2 (in sequence of how he clicked).
My issue is how to send the data to server? And, I can manage to do on click color change to make sure that the user clicked it. Or, even when he clicks, there is a line connecting the dots (like a stick shape).
How to do the same in HTML5, wherein every click he does on dots, is registered and then sent to the server.
One way would be to encode the state and then send it using an XMLHTTPRequest to the server.

MYSQL - Select most recent of column type entry

I have a table with columns:
s_Id (primary int), sup_type (int), sup_date (datetime), sup_req (int)
Values in sup_type so far range from 0-5.
How can I extract the most recent entry (by sup_date) of each sup_type (0-5).
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* s_Id * sup_type * sup_date * sup_req *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 1 * 0 * 2012-06-15 10:13:21 * 4 *
* 2 * 0 * 2012-06-15 11:22:01 * 4 *
* 3 * 1 * 2012-06-15 13:23:32 * 4 *
* 4 * 2 * 2012-06-16 08:04:29 * 4 *
* 5 * 1 * 2012-06-16 16:23:24 * 4 *
* 6 * 1 * 2012-06-17 13:14:05 * 4 *
* 7 * 3 * 2012-06-18 13:37:55 * 4 *
* 8 * 4 * 2012-06-19 13:21:52 * 4 *
* 9 * 4 * 2012-06-20 16:15:19 * 4 *
* 10 * 5 * 2012-06-20 16:17:37 * 4 *
* 11 * 0 * 2012-06-20 16:21:53 * 4 *
* 12 * 1 * 2012-06-20 16:28:13 * 4 *
* 13 * 3 * 2012-06-21 12:23:29 * 4 *
* 14 * 3 * 2012-06-22 07:26:41 * 4 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
I want to extract
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* s_Id * sup_type * sup_date * sup_req *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 4 * 2 * 2012-06-16 08:04:29 * 4 *
* 9 * 4 * 2012-06-20 16:15:19 * 4 *
* 10 * 5 * 2012-06-20 16:17:37 * 4 *
* 11 * 0 * 2012-06-20 16:21:53 * 4 *
* 12 * 1 * 2012-06-20 16:28:13 * 4 *
* 14 * 3 * 2012-06-22 07:26:41 * 4 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Thanks.
SELECT
b.*
FROM
(
SELECT sup_type, MAX(sup_date) AS maxsupdate
FROM tbl
GROUP BY sup_type
) a
INNER JOIN
tbl b ON
a.sup_type = b.sup_type AND
a.maxsupdate = b.sup_date
ORDER BY
b.s_Id